Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/sh
# if (a device is currently using 192.168.7.2) then
# Use 192.168.8.x on the host downstream port and slave upstream port
cat <<LOCAL_END >>/etc/network/interfaces
iface eth1 inet static
address 192.168.8.1
netmask 255.255.255.252
network 192.168.8.0
LOCAL_END
iptables --table nat --append POSTROUTING --out-interface usb0 -j MASQUERADE
iptables --append FORWARD --in-interface eth1 -j ACCEPT
echo 1 > /proc/sys/net/ipv4/ip_forward
# configure /dev/ttyACM0 and login
cat <<HOST_END >/dev/ttyACM0
cat <<DEVICE_END >>/etc/network/interfaces
iface usb0 inet static
address 192.168.8.2
netmask 255.255.255.252
network 192.168.8.0
gateway 192.168.8.1
DEVICE_END
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
route add default gw 192.168.8.1
HOST_END
# else
# Use 192.168.7.x on the host downstream port and slave upstream port
dhclient eth1
iptables --table nat --append POSTROUTING --out-interface usb0 -j MASQUERADE
iptables --append FORWARD --in-interface eth1 -j ACCEPT
echo 1 > /proc/sys/net/ipv4/ip_forward
# configure /dev/ttyACM0 and login
cat <<HOST_END >/dev/ttyACM0
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
route add default gw 192.168.7.1
HOST_END
# endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment