Ubuntu – Can’t use two network interfaces at the same time

14.04interfaceinternetnetworkingserver

I have a problem. First of all, I wan to set up a server on Ubuntu 14.04. I have 2 interfaces: eth0 for dhcp server and eth1 for internet connection. But if I connect to two networks at the same time, there isn't internet on PC. So I have to choose between server and internet. That's terrible, can anyone tell me how to close this issue?

/etc/network/interfaces:

auto lo eth0 eth1

iface lo inet loopback

iface eth0 inet static
address 172.16.1.100
netmask 255.255.255.0
broadcast 172.16.1.255
gateway 172.16.1.254

sudo route outputs:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.0.1     0.0.0.0         UG    0      0        0 eth1
192.168.0.0     *               255.255.255.0   U     1      0        0 eth1

UPD:
ifconfig outputs:

eth0      Link encap:Ethernet  HWaddr 90:e6:ba:46:1d:50  
          inet6 addr: fe80::92e6:baff:fe46:1d50/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1110 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:184287 (184.2 KB)

eth1      Link encap:Ethernet  HWaddr 00:04:75:98:5f:da  
          inet addr:192.168.0.101  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::204:75ff:fe98:5fda/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:14498 errors:0 dropped:0 overruns:2 frame:0
          TX packets:13096 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:9710708 (9.7 MB)  TX bytes:1840400 (1.8 MB)
          Interrupt:18 Base address:0x4c00 

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:4398 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4398 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:527890 (527.8 KB)  TX bytes:527890 (527.8 KB)

Best Answer

Configuring the output of ifconfig and the comments given to my first answer, I think that the problem is related to way you configure your NIC's in /etc/network/interfaces.

As you don't have any specific configuration for eth1 in /etc/network/interfaces, I suppose that your modem is giving to your server the IP info via DHCP. As per the route ouput, you get your default gateway pointing to the modem so to Internet.

But on your /etc/network/interfaces file for the eth0 you have also a default gateway configured (statement gateway 172.16.1.254).

You cannot have two default gateway on a system. The assignment of the default gateway on eth1 disable the static configuration of eth0, reason why there is no IP for eth0 in the ifconfig output and why Internet works and the internal network no more.

You will have to remove the line gateway 172.16.1.254 and try again.

By doing so, of course, if you have more than one subnet on the internal LAN you won't be able to reach them anymore. Unless you configure static route towards all of these subnets on your server :

sudo route add -net A.B.C.D gw 172.16.1.254

you can add the route command in a script saved under /etc/network/if-up.d to be run each time an interface goes up.

Related Question