Skip to content

Instantly share code, notes, and snippets.

@tiagoshibata
Created December 27, 2016 20:10
Show Gist options
  • Save tiagoshibata/1fc2a4d0cb41d6e906da23b4d9393ae7 to your computer and use it in GitHub Desktop.
Save tiagoshibata/1fc2a4d0cb41d6e906da23b4d9393ae7 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
if (( $# < 2 )) ; then
echo "Usage: $0 jetson_interface network_access_interface"
fi
if [ ! -f /etc/dhcpd.conf ] ; then
DHCPD_CONF="#option domain-name-servers 8.8.8.8, 8.8.4.4;
#option routers 10.8.0.1;
option subnet-mask 255.255.255.0;
subnet 10.8.0.0 netmask 255.255.255.0 {
range 10.8.0.10 10.8.0.250;
}"
echo '/etc/dhcpd.conf not found, press enter to populate with:'
echo $DHCPD_CONF
read
echo $DHCPD_CONF > /etc/dhcpd.conf
fi
jetson=$1
network=$2
ip link set up dev $jetson
ip addr add 10.8.0.1/24 dev $jetson
sysctl net.ipv4.ip_forward=1
dhcpd
iptables -t nat -A POSTROUTING -o $network -j MASQUERADE
iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $jetson -o $network -j ACCEPT
echo 'If the default route on the client is not configured, run:'
echo 'ip route add 0/0 via 10.8.0.1 dev eth0'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment