Skip to content

Instantly share code, notes, and snippets.

@jadonk
Forked from RobertCNelson/gist:3e526af326660604a71f
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jadonk/536b6550a63723ff2016 to your computer and use it in GitHub Desktop.
Save jadonk/536b6550a63723ff2016 to your computer and use it in GitHub Desktop.
#!/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