2019-09-29 07:26:27 +00:00
|
|
|
#!/usr/bin/env bash
|
2019-09-24 15:50:27 +02:00
|
|
|
|
|
|
|
# name of the ethernet gadget interface on the host
|
|
|
|
USB_IFACE=${1:-enp0s20f0u1}
|
|
|
|
USB_IFACE_IP=10.0.0.1
|
|
|
|
USB_IFACE_NET=10.0.0.0/24
|
|
|
|
# host interface to use for upstream connection
|
|
|
|
UPSTREAM_IFACE=${2:-enxe4b97aa99867}
|
|
|
|
|
2019-09-29 01:41:49 +01:00
|
|
|
ip addr add "$USB_IFACE_IP/24" dev "$USB_IFACE"
|
|
|
|
ip link set "$USB_IFACE" up
|
2019-09-24 15:50:27 +02:00
|
|
|
|
2019-09-29 01:41:49 +01:00
|
|
|
iptables -A FORWARD -o "$UPSTREAM_IFACE" -i "$USB_IFACE" -s "$USB_IFACE_NET" -m conntrack --ctstate NEW -j ACCEPT
|
2019-09-24 15:50:27 +02:00
|
|
|
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
|
|
|
|
iptables -t nat -F POSTROUTING
|
2019-09-29 01:41:49 +01:00
|
|
|
iptables -t nat -A POSTROUTING -o "$UPSTREAM_IFACE" -j MASQUERADE
|
2019-09-24 15:50:27 +02:00
|
|
|
|
|
|
|
echo 1 > /proc/sys/net/ipv4/ip_forward
|