Created
August 30, 2018 11:48
-
-
Save millsp/b9d8998c4446554de1c721ec74171de5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Bridge two network interfaces together | |
ip_address="192.168.2.1" | |
netmask="255.255.255.0" | |
dhcp_range_start="192.168.2.2" | |
dhcp_range_end="192.168.2.100" | |
dhcp_time="12h" | |
ifaceA="eth0" | |
ifaceB="eth1" | |
sudo systemctl start network-online.target &> /dev/null | |
sudo iptables -F | |
sudo iptables -t nat -F | |
sudo iptables -t nat -A POSTROUTING -o $ifaceB -j MASQUERADE | |
sudo iptables -A FORWARD -i $ifaceB -o $ifaceA -m state --state RELATED,ESTABLISHED -j ACCEPT | |
sudo iptables -A FORWARD -i $ifaceA -o $ifaceB -j ACCEPT | |
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" | |
sudo ifconfig $ifaceA $ip_address netmask $netmask | |
# Remove default route created by dhcpcd | |
sudo ip route del 0/0 dev $ifaceA &> /dev/null | |
sudo systemctl stop dnsmasq | |
sudo rm -rf /etc/dnsmasq.d/* &> /dev/null | |
echo -e "interface=$ifaceA\n\ | |
bind-interfaces\n\ | |
server=8.8.8.8\n\ | |
domain-needed\n\ | |
bogus-priv\n\ | |
dhcp-range=$dhcp_range_start,$dhcp_range_end,$dhcp_time" > /etc/dnsmasq.d/custom-dnsmasq.conf | |
sudo systemctl start dnsmasq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment