Transform Ubuntu Desktop in a Router : How to invert your desktop in a Router

Keywords : Transform Ubuntu in a Router, How to invert your desktop in a Router, IP Forwarding and Masquerading,  Router Ubuntu

Why to Transform Ubuntu Desktop in a Router ? The answer is simple: For fun as well as learn new things. 😉

In this tutorial I’ll show How to invert your desktop in a Router.

This can be helpful to utilize your old desktop as it won’t require much hardware. You can setup your own router, can implement much secure firewall, setup different services and list go on. Once you learn basics, you can utilize this as you want. 🙂

In this tutorial, I’ll use Ubuntu Desktop edition as operating system. People may argue on using desktop edition instead of Server edition, so my reasons to choose desktop edition are:

  • Many users may feel difficulty to use server edition.

  • Home users mostly install desktop edition.

  • This post also address those users who are newbies and have less experience with Linux’s command prompt.

  • Advance users can move with server edition later as basics will be same.

 Note that you will require a desktop/laptop with :

  1. Ubuntu desktop edition istalled in it

  2. Two NIC cards, one for external interface(internet) another one for internal interface(local network)

 Users who have one WiFi NIC and one ether-net NIC , can also follow this post. Please check:

  • If they are having internet connection on wi-fi and their ethernet NIC is free to use in local network, that’s fine.

  • If they have internet on ethernet port and want to use wi-fi as AP for local network then

    Check if their WiFi card support “master” mode, if yes , then we have no problem

  1. Open a terminal and give command

$ ip addr

$ iwconfig

$ sudo iplink set dev down

$ sudo iwconfig mode master

First command is to know what interfaces you have.

Second command “iwconfig” will tell you, which interface is your wi-fi interface.

Rest of the commands to set your wi-fi card in master mode.

  1. If no, then they have to use “hostapd” package to move on.

Those who don’t have Ubuntu installed already, can make their system dual-boot and install Ubuntu. [A separate post will be uodated soon regarding making a dual-boot system.. till then Google for it.. ;)]

Well, everything is set to go? Ok. Follow these steps:

  1. Know what are your internet settings i.e ip-address etc. Using ifconfig. See this post for more refernce:

    How to do URL Blocking / Content Filtering / ParentalLock

  2. Now decide what ip-address you will keep for your router. It shold not match/come in your internet ip-address range. Choose only from private ip-addresses. For this tutorial I am taking following:





    Broadcast Address

  3. Know your avilable interfaces and see which interface is being used for which purpose(inteanal or external). Here I am assuming following, you check it with your seetings and use the same.


    Type and use


    External- connected to a router or modem for internet


    Internal- connected to a switch/hub or another computer

  4. If you have more than two NIC and all are in use then we have to use bridge-utility. This will be covered later in this tutorial.

  5. Now take a backup of your old network settings in case anything goes wrong. Type this command in terminal:

  6. Open ‘/etc/network/interfaces’ file and replace text of this file with the text given below:

  • If you have Dynamic ip-address (DHCP)

    # Set up the local loopback interface

    auto lo

    iface lo inet loopback

    # Set up the External interface, I am taking eth0 replace it

    #with your interface

    auto eth0

    iface eth0 inet dhcp

  • If you have static ip-address

# Set up the local loopback interface

auto lo

iface lo inet loopback

# Set up the External interface, I am taking eth0 replace it

#with your interface

#Change with Numeric settings provided by your Internet provider

auto eth0

iface eth0 inet static






  1. Restart the network services and test whether this is working or not.

$ sudo /etc/init.d/networking restart

$ ping

 You should see output like this:

  1. Open “/etc/network/interfaces” file again and append following lines:

  • If your going to use wired NIC as an internal interface then append following lines

# Set up the Internal interface, I am taking eth1 replace it

#with your interface

auto eth1

iface eth0 inet static






  • If you are going to use wi-fi as internal interface then append following:

    # Set up internal interface using wi-fi

    auto wlan0

    iface wlan0 inet static

    wireless-mode master

    wireless-essid “Techawarey”

    wireless-channel 1





    You have set-up “eth1” as static as your machine has DHCP Server to assign ip’s to client machines. If you don’t have DHCP server installed yet, please follow this post  as it’s necessary to proceed further.

    How to install and configure DHCP-Server in Linux/Ubuntu

  1. As both interfaces has configured, now we have to connect them in order to make a router. For this we are going to use “IP forwarding and Masquerading” technique. Open a file using gedit, name it as “” and copy and paste following in it. This is a script from 

echo -e “\n\nLoading simple rc.firewall-iptables version $FWVER..\n”






echo ” External Interface: $EXTIF”

echo ” Internal Interface: $INTIF”


#== No editing beyond this line is required for initial MASQ testing ==

echo -en ” loading modules: “

echo ” – Verifying that all kernel modules are ok”


echo “———————————————————————-“

echo -en “ip_tables, “

$MODPROBE ip_tables

echo -en “nf_conntrack, “

$MODPROBE nf_conntrack

echo -en “nf_conntrack_ftp, “

$MODPROBE nf_conntrack_ftp

echo -en “nf_conntrack_irc, “

$MODPROBE nf_conntrack_irc

echo -en “iptable_nat, “

$MODPROBE iptable_nat

echo -en “nf_nat_ftp, “

$MODPROBE nf_nat_ftp

echo “———————————————————————-“

echo -e ” Done loading modules.\n”

echo ” Enabling forwarding..”

echo “1” > /proc/sys/net/ipv4/ip_forward

echo ” Enabling DynamicAddr..”

echo “1” > /proc/sys/net/ipv4/ip_dynaddr

echo ” Clearing any existing rules and setting default policy..”

iptables-restore <<-EOF








-A FORWARD -i “$EXTIF” -o “$INTIF” -m conntrack –ctstate ESTABLISHED,RELATED -j ACCEPT





echo -e “\nrc.firewall-iptables v$FWVER done.\n”

  1. Save it and change it’s read write attribute:

$ chmod a+x

  1. Test the script using root access

$ sudo sh

$ ping

 If you get same result as you got earlier, your script is working. Connect with another system in the network and see if you can access internet from there or not. If yes, Congratulations…

you have Transform Ubuntu Desktop in a Router and have learnt How to invert your desktop in a Router.

If your script working well then make it auto-start when Ubuntu boots:

$ sudo cp /etc/init.d/

$ sudo ln -s /etc/init.d/ /etc/rc2,d/s95techawarey

 Now restart your system and see after restart you can still access internet from another system. If no, see you make that script executable properly.

For more information on this tutorial please visit: 

If you liked this post please like and share it.. 😉

If have any query please leave a comment. 🙂

Transform Ubuntu Desktop in a Router or How to invert your desktop in a Router – You have learnt basics, so you can add your firewall rules using iptables. I’ll post a tutotial on that soon.

Also you can run a web-server on this router and mangae/control your router and other services. For more on this topic, please see this Host a Local web-site on Linux/Ubuntu

2 Thoughts to “Transform Ubuntu Desktop in a Router : How to invert your desktop in a Router”

  1. iptv server

    Hello,nice share.

  2. […] Transform Ubuntu Desktop in a Router : How to invert your desktop in a Router […]

Leave a comment....