How to set up a linux server as a router

I have to go like Jack the ripper due several missing things that you have:

  1. If you client will use DHCP to get the IP's you need a DHCP server.

    iface eth0 inet dhcp

    In the clients this indicates that they will get their IP's from a DHCP server, if you didn't setup a DHCP server, either you should use fixed IP's or install a DHCP server.

  2. You lack of DNS servers configured in the clients. Either due the lack of DHCP server, or you may want to use a local DNS server for all your network.

  3. You didn't offered the iptables rules (the output of sudo iptables -L) but I could guess that you didn't activated the Masquerade rules, nor IP forwarding as described.

  4. The IP address of eth1 is not recommended. Any IP ended in 0 are typically the network itself, and most routers/firewall just get confused when these are used. Change it to 192.168.7.1 and you will mostly fine.

  5. Your broadcast value in the eth1 interface is not correct. Is sending packages to nowhere. The correct value (taking into account other values of the interface) is 192.168.7.255.

  6. Your options in the DHCP server are vicious. The ARP packages to your router will never reach. This is what you should have:

    default-lease-time 600;
    max-lease-time 7200;
    option subnet-mask 255.255.255.0;
    option broadcast-address 192.168.7.255;
    option routers 192.168.7.1; ## This should be the same value of the step 4
    option domain-name-servers 8.8.8.8;
    
    subnet 192.168.7.0 netmask 255.255.255.0 {
        range 192.168.7.10 192.168.7.25;
    }

Follow these and most likely you will have your router working.


Braiam answered my question, but I thought it would be helpful to put a thorough walkthrough here. Please update this if I have made any mistakes.

First make sure you have two ethernet cards (NICs) and update the /etc/network/interfaces file as such (do not mistake this for the /etc/networks file).

iface lo inet loopback                                                                                                                    

auto eth0
   iface eth0 inet static
   address 192.168.1.70
   netmask 255.255.255.0
   broadcast 192.168.1.255
   network 192.168.1.0
   gateway 192.168.1.1
   dns-nameservers 8.8.8.8

auto eth1
   iface eth1 inet static
   address 192.168.7.1
   netmask 255.255.255.0
   broadcast 192.168.7.255
   network 192.168.1.0

To find your gateway, broadcast and network, follow these instructions.

Next, go into the client and edit the /etc/network/interface (again, not /etc/networks) file for static ip first, to make sure that at least the NIC card is working.

iface eth0 inet static
address 192.168.7.75
netmask 255.255.255.0
network 192.168.7.0
broadcast 192.168.7.255
gateway 192.168.7.1

Change the values to match up with the above values. If it works, great, then use the instructions here but follow them exactly, as there are several dhcp files so don't mistake the folder /etc/dhcp with /etc/dhcp3 and so on.

Tags:

Networking