大网数据广告活动
服务器运维问答

Ubuntu, two NICs but only one with internet connection

· 52CE 我爱测

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.…

问题原文

原帖链接 · weyhei · CC BY-SA 4.0

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

已采纳解答

原帖链接 · Piotr P. Karwasz · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-12-30)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。