Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Share Wifi with Eth device
  4. #
  5. #
  6. # This script is created to work with Raspbian Stretch
  7. # but it can be used with most of the distributions
  8. # by making few changes.
  9. #
  10. # Make sure you have already installed `dnsmasq`
  11. # Please modify the variables according to your need
  12. # Don't forget to change the name of network interface
  13. # Check them with `ifconfig`
  14.  
  15. ip_address="192.168.2.1"
  16. netmask="255.255.255.0"
  17. dhcp_range_start="192.168.2.2"
  18. dhcp_range_end="192.168.2.100"
  19. dhcp_time="12h"
  20. eth="eth0"
  21. wlan="wlan0"
  22.  
  23. sudo systemctl start network-online.target &> /dev/null
  24.  
  25. sudo iptables -F
  26. sudo iptables -t nat -F
  27. sudo iptables -t nat -A POSTROUTING -o $wlan -j MASQUERADE
  28. sudo iptables -A FORWARD -i $wlan -o $eth -m state --state RELATED,ESTABLISHED -j ACCEPT
  29. sudo iptables -A FORWARD -i $eth -o $wlan -j ACCEPT
  30.  
  31. sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
  32.  
  33. sudo ifconfig $eth $ip_address netmask $netmask
  34.  
  35. # Remove default route created by dhcpcd
  36. sudo ip route del 0/0 dev $eth &> /dev/null
  37.  
  38. sudo systemctl stop dnsmasq
  39.  
  40. sudo rm -rf /etc/dnsmasq.d/*
  41.  
  42. echo -e "interface=$eth\n\
  43. bind-interfaces\n\
  44. server=8.8.8.8\n\
  45. domain-needed\n\
  46. bogus-priv\n\
  47. dhcp-range=$dhcp_range_start,$dhcp_range_end,$dhcp_time" > /etc/dnsmasq.d/custom-dnsmasq.conf
  48.  
  49. sudo systemctl start dnsmasq
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement