How To Configure Ubuntu As A Router?

Any Ubuntu server can be converted into a router by following few steps. This is possible only if your device has a separate network interface card for the internet and a different one for the local network. Continue reading to know about how to configure Ubuntu as a router.

  • Step 1 :Understand the idea that the two network interface cards are required. One for internet (10.10.6.204) and the other for the local network (10.10.6.0) with different IP addresses.
  • Step 2 :The computers connecting to the internet (192.168.1.8) and the local network (10.10.6.205) will also have different IP addresses.
  • Step 3 :On the desktop version, select System Settings and click the Network menu.
  • Step 4 :Select the Interface option and continue.
  • Step 5 :In case it is the server version, then launch the Terminal window on the screen by pressing Ctrl, Alt, and T altogether.
  • Step 6 :Input the below command and press Enter.

sudo vim /etc/network/interfaces

  • Step 1 :Following that, type the below command lines to edit the interfaces file and press the Enter key.
  • auto lo

    iface lo inet loopback

    auto eth0

    iface eth0 inet static

    address 10.10.6.203

    netmask 255.255.255.0

    gateway 10.10.6.203

    auto eth1

    iface eth1 inet static

    address 10.10.6.204

    netmask 255.255.255.0

    gateway 10.10.6.2

  • Step 2 :Now, you have to enable IP forwarding to route the two interfaces. For that, input the command and press Enter.
  • sudo sh –c echo 1 /proc/sys/net/ipv4/ip forward

  • Step 3 :Now, open edit the sysctl.conf file and include the below commands.
  • net.ipv4.conf.default.forwarding=1

    net.ipv4.conf.all.forwarding=1

  • Step 4 :Initiate the IP masquerade by entering the following command lines and press Enter after each line.
  • sudo iptables –t nat –A POSTROUTING –o eth1

    sudo iptables –A FORWARD –i eth1 –o eth0 –m state --state RELATED, ESTABLISHED -j ACCEPT

    sudo iptables –A FORWARD –i eth0 –o eth1 –j ACCEPT

  • Step 5 :Next, you have to save the above iptables rules. For this type the below command in the command line and press Enter.
  • iptables-save > /etc/iptables.rules

  • Step 6 :The computer starts to reboot, after which the changes are made on the system. Hopefully this would help you to configure Ubuntu as a router.