iptables - stereoboy/Study GitHub Wiki

On Host PC

sudo bash -exec "echo 1 > /proc/sys/net/ipv4/ip_forward"
sudo iptables -t nat -A POSTROUTING -o wlp4s0 -j SNAT --to 192.168.0.2 //<- Host PC's internet-conneced ip

sudo iptables  -t nat -S POSTROUTING
-P POSTROUTING ACCEPT
-A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE
-A POSTROUTING -j LIBVIRT_PRT
-A POSTROUTING -o wlp4s0 -j SNAT --to-source 192.168.0.2 //<- Appended Entry

// disable firewall if the setting above is not working
sudo ufw disable

ssh <id>@<ip>

On Host PC (Another Setup)

sudo iptables --table nat --append POSTROUTING --out-interface wlp5s0 -j MASQUERADE
sudo iptables --append FORWARD --in-interface usb0 -j ACCEPT

// disable firewall if the setting above is not working
sudo ufw disable

iptables

  • Delete a entry from iptables
sudo iptables  -t nat -S POSTROUTING
-P POSTROUTING ACCEPT
-A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE
-A POSTROUTING -j LIBVIRT_PRT
-A POSTROUTING -o usb0 -j SNAT --to-source 192.168.0.2
-A POSTROUTING -o wlp4s0 -j SNAT --to-source 192.168.0.2

sudo iptables  -t nat -D POSTROUTING 3
-P POSTROUTING ACCEPT
-A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE
-A POSTROUTING -j LIBVIRT_PRT
-A POSTROUTING -o wlp4s0 -j SNAT --to-source 192.168.0.2
⚠️ **GitHub.com Fallback** ⚠️