6

I am having issue with my Ubuntu because I am unable to use wget or access any website with my current setup.

I have two NICs, enp2s0 and enp2s1.

enp2s0 is connected to the internet but connected to a NAT router (IP Address: 192.168.1.2)

While for enp2s1, it is connected to another router buth with no internet since it will only be used for internal networking (IP Address: 10.0.0.5)

If the only NIC connected is the one with the internet (enp2s0), the computer can access any website. But once the second NIC is connected (enp2s0 & enp2s1), the computer doesn't load any webpage, wget, or even apt-get update or apt-get install.

Is this something to do with iptables or routing? Help me out as I am new with this.

Here are some current details of the machine:

$ ip route show
default via 192.168.1.1 dev enp2s0 proto dhcp metric 20100
default via 10.0.0.1 dev enp2s1 proto dhcp metric 20101
169.254.0.0/16 dev enp2s0 scope link metric 1000
192.168.1.0/24 dev enp2s0 proto kernel scope link src 192.168.1.2 metric 100
10.0.0.0/24 dev enp2s1 proto kernel scope link src 10.0.0.5 metric 101

$ iptables -S -t nat; iptables -S
-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT

$ ip r
default via 192.168.1.1 dev enp2s0 proto dhcp metric 20100
default via 10.0.0.1 dev enp2s1 proto dhcp metric 20101
169.254.0.0/16 dev enp2s0scope link metric 1000
192.168.1.0/24 dev enp2s0 proto kernel scope link src 192.168.1.2 metric 100
10.0.0.0/24 dev enp2s1  proto kernel scope link src 10.0.0.5 metric 101

/etc/network/interfaces

auto lo
iface lo inet loopback

Since this is a newly installed ubuntu, we haven't maintained anything in the machine yet.

For the network 10.0.0.0/24 we wanted to have network connectivity for each device connected, (i.e., file sharing, web server checking) and it is completely isolated from internet.....

10.0.0.5 was given to the enp2s1 NIC since the router has its own DHCP, and 10.0.0.1 is the router gateway

7
  • 1
    Could you add the routes : "ip route show" and "iptables -S -t nat; iptables -S"
    – Dom
    Commented Dec 30, 2019 at 14:20
  • 2
    You have to set your default gateway correctly, please add the output of ip r
    – Lenniey
    Commented Dec 30, 2019 at 14:20
  • Here's a screenshot of the result imgur.com/a/iCtFVKv
    – weyhei
    Commented Dec 30, 2019 at 15:30
  • @Dom I have updated the above question. What happen here is when the both NICs are connected, the whole computer seem to have no internet connection. Also, above is the screenshot of the requested commands.
    – weyhei
    Commented Dec 30, 2019 at 18:00
  • 2
    You have a default route for the interface with no internet. You need to remove it, or prevent it from being added.
    – Zoredache
    Commented Dec 30, 2019 at 18:16

1 Answer 1

5

As pointed out in the above comments you have two default routes (via 192.168.1.1 and 10.0.0.1) but only the first one connects to the Internet. If the routing table remains as you posted you will have an Internet connection: whenever you have two routes for the same destination, the one with smaller metric wins.

However, since the metric is not assigned by you, but by the DHCP clients, the value of metric depends on the order in which the interfaces are brought up. I would change your configuration to a static one. Add to the file /etc/network/interfaces the following lines:

auto enp2s0
iface enp2s0 inet static
    address 192.168.1.2
    netmask 24
    gateway 192.168.1.1

auto enp2s1
iface enp2s1 inet static
    address 10.0.0.5
    netmask 24

and restart networking (sudo systemctl restart networking).

PS: This is the oldest way to configure networking on Ubuntu/Debian. On a new Ubuntu there is certainly also NetworkManager and systemd-networkd (in order of appearance). There is also an equivalent configuration for those two.

2
  • This worked somehow. But I think I only got one issue here, and that is DNS setting. I tried to do nslookup google.com, and the resolver being used is 127.0.0.53 so, I tried nslookup google.com 8.8.8.8 and it could lookup for the domain name......First thing I added dns-nameserver 8.8.8.8 8.8.4.4 in the /etc/network/interfaces and restarted but it didn't work. DNS would only work when I add nameserver 8.8.8.8 nameserver 8.8.4.4 in /etc/resolv.conf but since this is a dynamic file, it is removed whenever the computer is rebooted. How do I make a permanent fix for this?
    – weyhei
    Commented Dec 30, 2019 at 20:51
  • So you met systemd-resolved. It runs a small DNS resolver on the local address 127.0.0.53 and forwards everything to the probably wrong DNS servers he gets from DHCP. You can delete the symlink /etc/resolv.conf and create a real file instead. systemd-resolved will not touch it. Commented Dec 30, 2019 at 21:03

You must log in to answer this question.

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