使用 Bond0 进行路由、DNS 解析

使用 Bond0 进行路由、DNS 解析

当我在设备上从 dhcp 切换到静态 IP 时,我在 18.04 服务器上遇到了问题。我之所以要切换,是因为尽管我的路由器为我的主接口 (eth0) 保留了一个静态 IP 地址,但我还是随机地在服务器上获取了一个新 IP 地址。我切换到了静态,现在我在解析/路由到网关时遇到了问题。我的设置有三个接口 (eth0 (主接口)、eth1、eth3)。不知道真正导致 bond0 实施问题的原因是什么。数据在网络内移动正常,但在外部则不然,因此我无法更新系统,除非我切换回 dhcp 并接受随机变化的 dhcp 地址。

cat /etc/network/interfaces
# ifupdown has been replaced by netplan(5) on this system.  See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
#    sudo apt install ifupdown
#
# loopback
auto lo
iface lo inet loopback

# primary network card
auto eth0
iface eth0 inet manual
bond-master bond0
bond-primary eth0

# second network interface card
auto eth1
iface eth1 inet manual
bond-master bond0

# third network interface card
auto eth3
iface eth3 inet manual
bond-master bond0

# bond0 network interface
auto bond0
iface bond0 inet static
        address 192.168.0.100
        gateway 192.168.0.1
        netmask 255.255.255.0
        dns-nameservers 192.168.0.1 208.67.222.222 208.67.220.220
                bond_mode 6
                bond-miimon 100
                bond-slaves none

ifconfig
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        inet 192.168.0.100  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::6ef0:49ff:fe5e:c194  prefixlen 64  scopeid 0x20<link>
        ether 6c:f0:49:5e:c1:94  txqueuelen 1000  (Ethernet)
        RX packets 298900  bytes 19550931 (19.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2089172  bytes 3153193403 (3.1 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 6c:f0:49:5e:c1:94  txqueuelen 1000  (Ethernet)
        RX packets 354297  bytes 21749288 (21.7 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 15785  bytes 15597970 (15.5 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=6147<UP,BROADCAST,SLAVE,MULTICAST>  mtu 1500
        ether 6c:f0:49:5e:c9:95  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth3: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 00:14:5e:77:45:c6  txqueuelen 1000  (Ethernet)
        RX packets 296791  bytes 19306412 (19.3 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4487992  bytes 6786908424 (6.7 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  memory 0xfdee0000-fdf00000

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 7759  bytes 1630081 (1.6 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7759  bytes 1630081 (1.6 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

route
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 bond0
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 bond0

root@mediasvr:/home/xxxx# ping www.cnn.com
ping: www.cnn.com: Temporary failure in name resolution

root@mediasvr:/home/xxxx# nslookup www.cnn.com
;; connection timed out; no servers could be reached

root@mediasvr:/home/xxxx# ping 192.168.0.100
PING 192.168.0.100 (192.168.0.100) 56(84) bytes of data.
64 bytes from 192.168.0.100: icmp_seq=1 ttl=64 time=0.059 ms
64 bytes from 192.168.0.100: icmp_seq=2 ttl=64 time=0.053 ms

--- 192.168.0.100 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1028ms
rtt min/avg/max/mdev = 0.053/0.056/0.059/0.003 ms

**root@mediasvr:/home/xxxx# ping 192.168.0.1**
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
From 192.168.0.100 icmp_seq=4 Destination Host Unreachable
From 192.168.0.100 icmp_seq=5 Destination Host Unreachable
From 192.168.0.100 icmp_seq=6 Destination Host Unreachable
From 192.168.0.100 icmp_seq=16 Destination Host Unreachable
From 192.168.0.100 icmp_seq=17 Destination Host Unreachable
From 192.168.0.100 icmp_seq=18 Destination Host Unreachable
From 192.168.0.100 icmp_seq=19 Destination Host Unreachable
From 192.168.0.100 icmp_seq=20 Destination Host Unreachable

--- 192.168.0.1 ping statistics ---
23 packets transmitted, 0 received, +8 errors, 100% packet loss, time 22504ms

root@mediasvr:/home/xxxx# systemd-resolve --status
Global
         DNS Servers: 192.168.0.1
                      208.67.222.222
                      208.67.220.220
          DNSSEC NTA: 10.in-addr.arpa
                      16.172.in-addr.arpa
                      168.192.in-addr.arpa
                      17.172.in-addr.arpa
                      18.172.in-addr.arpa
                      19.172.in-addr.arpa
                      20.172.in-addr.arpa
                      21.172.in-addr.arpa
                      22.172.in-addr.arpa
                      23.172.in-addr.arpa
                      24.172.in-addr.arpa
                      25.172.in-addr.arpa
                      26.172.in-addr.arpa
                      27.172.in-addr.arpa
                      28.172.in-addr.arpa
                      29.172.in-addr.arpa
                      30.172.in-addr.arpa
                      31.172.in-addr.arpa
                      corp
                      d.f.ip6.arpa
                      home
                      internal
                      intranet
                      lan
                      local
                      private
                      test

Link 8 (bond0)
      Current Scopes: none
       LLMNR setting: yes
MulticastDNS setting: no
      DNSSEC setting: no
    DNSSEC supported: no

Link 6 (eth4)
      Current Scopes: none
       LLMNR setting: yes
MulticastDNS setting: no
      DNSSEC setting: no
    DNSSEC supported: no

Link 5 (eth3)
      Current Scopes: none
       LLMNR setting: yes
MulticastDNS setting: no
      DNSSEC setting: no
    DNSSEC supported: no

Link 4 (eth2)
      Current Scopes: none
       LLMNR setting: yes

我正在附加所要求的附加信息。

root@mediasvr:/etc/netplan# cat 50-cloud-init.yaml

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
network:
    version: 2
    renderer: networkd
    ethernets:
      bond0:
        dhcp4: no
        dhcp6: no
        addresses: [192.168.0.100/24]
        gateway4: 192.168.0.1
        nameservers:
            addresses: [208.67.222.222, 208.67.220.220]

root@mediasvr:/etc/netplan# ls -al /etc/resolv.conf

lrwxrwxrwx 1 root root 27 Apr 12 14:40 /etc/resolv.conf -> /run/resolvconf/resolv.conf

root@mediasvr:/etc/netplan# cat /etc/resolv.conf

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.

nameserver 208.67.222.222,
nameserver 208.67.220.220
nameserver 127.0.0.53

@heynnema-更新

因此我更改了接口和 .yaml 文件并应用了 netplan 而没有错误(调试),但是,我仍然遇到网络问题:

  1. 我可以 ping 我的接口
  2. 根据 /proc/net/bonding/bond0 (静态),团队债券是没问题的,但是,
  3. 路线命令延迟弹出
  4. 无法 ping 通网关
  5. 无法解析 DNS

以下是我执行的更新:

猫/等/网络/接口

# ifupdown has been replaced by netplan(5) on this system.  See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
#    sudo apt install ifupdown
#
# loopback
auto lo
iface lo inet loopback

/etc/netplan/50-cloud-init.yaml

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
network:
  version: 2
    renderer: networkd
    ethernets:
      eth0:
        dhcp4: no
      eth1:
        dhcp4: no
      eth3:
        dhcp4: no
    bonds:
      bond0:
        interfaces: [eth0, eth1, eth3]
        addresses: [192.168.0.100/24]
        gateway4: 192.168.0.1
        nameservers:
          search: [local]
          addresses: [208.67.222.222, 208.67.220.220]
        parameters:
          mode: balance-alb
          mii-monitor-interval: 1
          gratuitious-arp: 5

@heynnema - 更新(感谢您的专业知识/时间。我相信我们离解决这个问题越来越近了)

我启用了一个额外的未使用接口,并在 yaml 文件中将其设置为 dhcp,并通过 netplan 应用。我在现有的 3 个网卡 (eth1-eth3) 上保持相同的组绑定

eth4: dhcp4: true 可选:true

root@mediasvr:/home/raul# 路线

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         _gateway        0.0.0.0         UG    0      0        0 bond0
default         _gateway        0.0.0.0         UG    100    0        0 eth4
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth4
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 bond0
_gateway        0.0.0.0         255.255.255.255 UH    100    0        0 eth4

root@mediasvr:/home/raul# netstat -rn

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG        0 0          0 bond0
0.0.0.0         192.168.0.1     0.0.0.0         UG        0 0          0 eth4
192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 eth4
192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 bond0
192.168.0.1     0.0.0.0         255.255.255.255 UH        0 0          0 eth4

root@mediasvr:/home/raul# 跟踪路由 192.168.01

traceroute to 192.168.01 (192.168.0.1), 64 hops max
  1   192.168.0.1  0.569ms  0.359ms  0.370ms
  1. 我能够对网关执行 ping 操作/跟踪路由,而之前却无法做到这一点。
  2. 我可以执行 DNS 查找
  3. 我可以通过 dhcp 地址远程 ssh 到服务器

但是,4. 我无法连接到存储库以获取更新 - 连接(113:没有到主机的路由)无法连接到 archive.ubuntu.com:80 (91.189.88.149)。5. 我无法连接到现在正在监听 dhcp 地址的 plex 媒体服务器

tcp        0      0 mediasvr:32400          192.168.0.11:10558      TIME_WAIT
tcp        0      0 mediasvr:49206          mediasvr:32400          ESTABLISHED

@heynnema-更新了 yaml 文件(您是否愿意在聊天中继续此操作?)

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
network:
  version: 2
    renderer: networkd
    ethernets:
      eth0:
        dhcp4: no
        optional: true
      eth1:
        dhcp4: no
        optional: true
      eth3:
        dhcp4: no
        optional: true
      eth4:
        dhcp4: true
        optional: true  
    bonds:
      bond0:
        interfaces: [eth0, eth1, eth3]
        addresses: [192.168.0.100/24]
        gateway4: 192.168.0.1
        nameservers:
          search: [local]
          addresses: [192.168.0.1, 208.67.222.222, 208.67.220.220]
        parameters:
          mode: balance-alb
          mii-monitor-interval: 1
          gratuitious-arp: 5

@heynnema - 更新 - 我已采纳您对 yaml 更改的建议。看来它改进了几件事。具体来说;

  1. 我现在可以对 eth4 和 bond0 进行内部/外部 ping 操作以及对网关进行 ping 操作。
  2. DNS 解析有效
  3. 我可以通过 SSH 进入服务器

但是,1. Plex 使用它看到的第一个网卡,在本例中是 dhcp 接口 2. 我无法与互联网交互

UPDATED Yaml file
    network:
      version: 2
      renderer: networkd
      ethernets:
        eth0:
         dhcp4: no
         optional: true
        eth1:
         dhcp4: no
         optional: true
        eth3:
         dhcp4: no
         optional: true
        eth4:
         dhcp4: true
         optional: true
      bonds:
        bond0:
         interfaces: [eth0, eth1, eth3]
         addresses:
           - 192.168.0.100/24
         #gateway4: 192.168.0.1
         routes:
           - to: 0.0.0.0/0
             via: 192.168.0.1
             metric: 100
         nameservers:
           search: [local]
           addresses: [208.67.222.222, 208.67.220.220]
         parameters:
           mode: balance-alb
           mii-monitor-interval: 1
           gratuitious-arp: 5

root@mediasvr:/home/raul# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG        0 0          0 bond0
0.0.0.0         192.168.0.1     0.0.0.0         UG        0 0          0 eth4
0.0.0.0         192.168.0.1     0.0.0.0         UG        0 0          0 bond0
192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 eth4
192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 bond0
192.168.0.1     0.0.0.0         255.255.255.255 UH        0 0          0 eth4

答案1

我发现在 Ubuntu Server 18.04 中,有一种与外部连接进行通信的新方法。如果您查看 /etc/netplan/,就会看到一个名为 50-cloud-init.yaml 的文件。

据说,这个文件需要修改才能与静态 IP 地址配合使用。我实际上发布了一个熟悉的问题,有位朋友帮忙了。请参见此处:回复:让 Ubuntu 服务器显示网页 URL 而不是仅显示我的 IP 地址

...

如果这有帮助,那么这是一个很好的标记。我还在这个网站上找到了一些类似的实例,它们专用于 Ubuntu 的服务器端。

塞斯

PS 我还没有 100% 解决这个静态 IP 问题的方法,但是我的页面现在已经启动并运行,路由器上有“端口转发”。我实际上尝试更改我的 .yaml 文件,即我之前在 /etc/netplan/ 中描述的文件,但没有成功。查看 netplan(5) 以获取入门信息。以及关于守护进程的一组很好的结论。此外,如果这是一个很大的问题,您可以让 no-ip 等第三方为您托管您的静态 IP。

...

所以,

对于静态 IP 地址:使用您最喜欢的编辑器和文件 /etc/netplan/50-cloud-init.yaml 或使用第三方如 no-ip.com。

要设置您的 DNS:使用 bind9,例如 sudo apt install bind9。您必须取消注释 /etc/bind/named.conf.options 中的文件并设置您的 IP:

   forwarders { 
  8.8.8.8; 
  8.8.4.4; 
};

我一直在阅读 Lacroix 的书《精通 Ubuntu Server》。该书的特定章节专门介绍了 Ubuntu Server 的新版本。

无论如何...上面的代码不应该被注释掉,它本来就是针对谷歌的 DNS 服务器的。你也可以将它们指向你的 ISP 的 DNS 服务器。

现在...使用 重新启动绑定服务sudo systemctl restart bind9

如果这太清楚或太模糊,请告诉我。随着时间的推移,我会尝试更清楚地了解您的情况。如果这支持您的事业,请告诉我。

哦!您的服务器使用的是路由器和接入点,还是只使用路由器?

要创建带有接入点和路由器的网关,请使用以下命令:

echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward

我也从书中得到了这个命令。

现在,要使该命令在重启后起作用,请转到文件 /etc/sysctl.conf 进行更改。使用此更改。

#net.ipv4.ip_forward=1

到:

net.ipv4.ip_forward=1

只需取消注释井号即可。

这应该会阻止因 Ubuntu Server 而取消服务器的重启。

答案2

  • 我假设 eth0 是你的 WAN 连接

  • 我没有在 .yaml 中绑定 3 个接口

  • 让 eth0 通过以下方式获取任何 IP 地址DHCP4 服务现在

  • 我们可以为 eth0 设置路由器保留地址之后...

    • sudo lshw -C networkifconfigip addr# 识别 eth0 的正确 MAC
    • 设置路由器保留的 dhcp 使用该 MAC 地址和所需的 IP
  • 在此过程中需要进行一些调整

sudo netplan --debug generate# 生成配置文件

sudo netplan apply# 应用新配置

reboot# 并验证操作是否正确


network:
  version: 2
    renderer: networkd
    ethernets:
      eth0:
        dhcp4: true
        optional: true
      eth1:
        dhcp4: false
        optional: true
      eth3:
        dhcp4: false
        optional: true
      eth4:
        dhcp4: false
        optional: true
    bonds:
      bond0:
        interfaces: [eth1,eth3,eth4]
        addresses: [192.168.0.100/24]
        #gateway4: 192.168.0.1 # not used with routes
        routes:
          - to: 0.0.0.0/0
            via: 192.168.0.1
            metric: 100
        nameservers:
          search: [local]
          addresses: [208.67.222.222,208.67.220.220]
        parameters:
          mode: balance-alb
          mii-monitor-interval: 1
          gratuitious-arp: 5

相关内容