Ubuntu Internet Sharing

I have this specific configuration wherein I have a PC (urop) with two network interfaces. One connected to the internet. Second network interface connected to another PC (tx2). I can access internet on urop.  I can ssh to tx2 from urop.

I want to accomplish the following. To access the internet from tx2. tx2 need not be accessible from the internet. This blog gives a solution to exactly this.

Screenshot from 2018-01-09 12:58:12

The idea is to enable ip forwarding on urop. On tx2 set the gateway and nameserver.

On urop:

sudo iptables –table nat –append POSTROUTING –out-interface enx000ec6a1160e -j MASQUERADE
sudo iptables –append FORWARD –in-interface enp1s0 -j ACCEPT
sudo sysctl net.ipv4.ip_forward=1

On tx2:

sudo ip route add default via dev eth0
echo “nameserver” > /tmp/resolv.conf
sudo mv /tmp/resolv.conf /etc/


How to set static ip address at boot time:
Edit file /etc/network/interfaces

on urop (i7)

auto enp1s0
iface enp1s0 inet static

on tx2
auto eth0
iface eth0 inet static

Credit: Mr. Arpit Tolani (Principal Technical Support Engineer at Red Hat Inc. in Pune)


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s