36

Motivation:

I want to use my linux server instead of the average wireless router for several reasons

  1. I want to learn how to set up a more complete server on linux
  2. I don't want to have a modem, connected to a router, connected to a network switch
  3. I am sick and tired of having to unplug my router every 10 days because it just hangs
  4. I am sick and tired of buying routers only to realize they are missing something crucial, like port forwarding or static ip addressing (dhcp)

Set up:

Ultimately, the connection will come into a modem, and straight into my server through eth0, then eth1 will output to a network switch which all other client computers will connect to via ethernet cables (forget wireless for the moment). Currently, however, I am in an office building, and I have the connection coming into a modem, which goes into a router, which goes into a network switch, which then goes into eth0 as specified above.

Current Tutorials:

I looked at some tutorials (Ubuntu tutorial is the best one), and I have looked at some of the router questions here (ie. this one), but they all gloss over several key concepts, like:

  • What is eth1's relation to eth0? In /etc/network/interfaces do I have to tell eth1 to use eth0 as the network (generally it is the actual physical router address)?
  • Do I have to do anything to instruct eth1 to take the internet that comes into eth0 and pass it onto whoever wants it in the network switch?

Current Approach:

Here is my /etc/network/interfaces file on the server:

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 dhcp
   iface eth1 inet static
   address 192.168.7.0
   netmask 255.255.255.0
   broadcast 192.168.1.255
   network 192.168.1.0

And ifconfig tells me that both NICs are working fine:

eth0      Link encap:Ethernet  HWaddr 20:cf:30:55:a0:5f  
          inet addr:192.168.1.70  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::22cf:30ff:fe55:a05f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:11297 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16639 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:948633 (948.6 KB)  TX bytes:1274685 (1.2 MB)

eth1      Link encap:Ethernet  HWaddr 00:11:95:f7:f4:6d  
          inet addr:192.168.7.0  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::211:95ff:fef7:f46d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:243 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3231 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:29934 (29.9 KB)  TX bytes:213055 (213.0 KB)
          Interrupt:21 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:5348 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5348 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:470737 (470.7 KB)  TX bytes:470737 (470.7 KB)

wlan0     Link encap:Ethernet  HWaddr bc:f6:85:f8:70:5c  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

And here is what route -n returns on the server:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 eth1
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.7.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1

Then on the client I have

auto lo
iface lo inet loopback
iface eth0 inet dhcp

But it is not being assigned an ip address.

EDIT: Here is the isc-dhcp-server configuration file located at /etc/dhcp3/dhcpd.con which I copied mostly from this site.

# Sample /etc/dhcpd.conf                                                                                                                                                  
# (add your comments here) 
default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option routers 192.168.1.254;
option domain-name-servers 192.168.1.1, 192.168.1.2;
option domain-name "mydomain.example";

subnet 192.168.7.0 netmask 255.255.255.0 {
   range 192.168.7.10 192.168.7.25;
}  

EDIT: Output of sudo iptables -L

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy DROP)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
ACCEPT     all  --  anywhere             anywhere            
LOG        all  --  anywhere             anywhere             LOG level warning

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Question:

What crucial steps/components am I missing in this setup?

7
  • What dhcpd are you using?
    – TML
    Nov 14, 2013 at 0:56
  • @TML From my understanding dhcp (and thus dhcpd) is not mandatory, and is only meant for centralizing all static ips at the server (as opposed to changing the /etc/network/interfaces file in every host). Therefore, I have decided to not experiment with that until this works. I do however have dhcp3-server installed, as well as isc-dhcp-server
    – puk
    Nov 14, 2013 at 0:59
  • If you want the client to get an IP address from dhcp, you need to run a dhcpd; you should post the configuration for whichever of these dhcpd's is currently the active one, as that's where the source of the problem will be re: client not getting an IP. Personally, I would recommend dnsmasq, as it also brings with it some useful features for doing internal DNS resolution.
    – TML
    Nov 14, 2013 at 1:03
  • @TML I added the dhcpd.conf file and indicated that I am using isc-dhcp-server
    – puk
    Nov 14, 2013 at 1:14
  • 1
    You should two more points: 5. I am sick and tired of having only partial control of the device. 6. I am sick and tired of having a router that could potentially have a backdoor. Point #6 is a real thing that can be right now in any router. Some routers do come with extra features such as hard-coded password or secretly listening to some port.
    – Ignas2526
    Jun 3, 2015 at 22:15

2 Answers 2

17

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.

12
  • Added output of sudo iptables -L to question
    – puk
    Nov 14, 2013 at 1:29
  • Not to be picky, but for the interests of any one else reading this answer, could you explain what some of these dhcpd.conf values are: line 4 192.168.7.255 and line 8 subnet 192.168.7.0
    – puk
    Nov 14, 2013 at 1:33
  • @puk that is too complex to explain in comments, but to put it nicely, .255 is the normally used broadcast address, any package sent to that direction will be sent to all the systems in the same subnets. Meaning that any package sent to 1.2.3.255 it will be received by any system which IP's start with 1.2.3 since all of them are in the same subnet en.wikipedia.org/wiki/Subnetwork#IPv4_subnetting
    – Braiam
    Nov 14, 2013 at 1:41
  • Not working. I want to see if the problem is dhcp or the network. Will do a static ip address to test. for the static ip on the client, do I use eth1's ip address as the gateway?
    – puk
    Nov 14, 2013 at 1:55
  • 1
    Probably because the broadcast and network on eth1 of the router are pointing to 192.168.1.x instead of 192.168.7.x; if you can't talk from eth1 on router to eth0 on client, DHCPACKs won't ever arrive at client (and it'll consequently never get the IP).
    – TML
    Nov 14, 2013 at 8:54
9

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .