Can't use two network interfaces at the same time

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)

Solution 1:

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.

Solution 2:

From what I understand of your post, you are connecting to Internet via eth1 and to your internal network via eth0. And your server is then playing the role of DHCP server and default gateway for your PC's to go the Internet.

First, on the PC, check that they've received correctly all DHCP settings, including the gateway. From your question, I assume it should be 172.16.1.100

Secondly, be sure that your eth1 is well connected to the Internet and well configured; this is obviously depending of your ISP.

Finally, the most important operation, you will have to enable IP forwarding between your two interfaces on the server. Without this, packet won't be routed between your PC's and the Internet :

Manual set-up :

sudo echo 1 > /proc/sys/net/ipv4/ip_forward

To have the IP forward flag automatically setup at boot time uncomment the line #net.ipv4.ip_forward=1 in /etc/sysctl.conf

You will have also to ensure that there are no IPtables firewall rules that block the traffic. Do :

iptables -L -n

to get a list of rules if any. I would first try this setup with all firewall rules disabled :

iptables -F

Solution 3:

I had similar issue, but my interfaces file was empty like this:

# The loopback network interface
auto lo
iface lo inet loopback

I managed to fix the issue by moving/removing the Wired connection file found: /etc/NetworkManager/system-connections/Wired connection 1

After reboot, was able to connect to both networks.