Ubuntu 22.04无法正确设置ipv6地址

Ubuntu 22.04无法正确设置ipv6地址

我正在尝试配置一个具有两个网络的 Ubuntu 22.04 服务器,一个使用 ipv4,一个使用 ipv6(双栈)。

这是我的/etc/网络/接口(我的文件中的ipv6地址是正确的,这里我替换了)

# The loopback network interface
auto lo
iface lo inet loopback

auto be0
iface be0 inet static
  address 10.0.100.138
  netmask 255.255.255.192
  network 10.0.100.128
  broadcast 10.0.100.191
  gateway 10.0.100.129

  post-up ip route flush cache
  post-down ip route flush cache
  post-up sleep 10s && ping -q -c 60 10.0.100.129 > /dev/null 2>&1 || true &

iface be0 inet6 static
  pre-up modprobe ipv6
  address 0x00:x00:000:0000::4
  netmask 64

  post-up ip -6 route add table be default via 0x00:x00:000:0000::1 dev be0
  post-up ip -6 route add table be 0x00:x00:000:0000::/64 dev be0 proto kernel scope link src 0x00:x00:000:0000::4
  post-up ip -6 rule add prio 10 from 0x00:x00:000:0000::4 lookup be
  pre-down ip -6 rule del from 0x00:x00:000:0000::4 lookup be
  pre-up ip -6 route flush table be
  post-up ip -6 route flush cache
  post-down ip -6 route flush cache

auto mgmt0
iface mgmt0 inet static
  address 10.0.100.44
  netmask 255.255.255.192
  network 10.0.100.0
  broadcast 10.0.100.63

  post-up ip route add table mgmt default via 10.0.100.1 dev mgmt0
  post-up ip route add table mgmt 10.0.100.0/26 dev mgmt0 proto kernel scope link src 10.0.100.44
  post-up ip rule add prio 20 from 10.0.100.44 lookup mgmt
  pre-down ip rule del from 10.0.100.44 lookup mgmt
  pre-up ip rule add prio 10000 to 10.245.253.29 lookup mgmt
  pre-down ip rule del to 10.245.253.29 lookup mgmt
  pre-up ip route flush table mgmt || /bin/true

  post-up ip route flush cache
  post-down ip route flush cache
  post-up sleep 10s && ping -q -c 60 10.0.100.1 > /dev/null 2>&1 || true &

网络服务重新返回此错误:

# systemctl status networking.service
× networking.service - Raise network interfaces
     Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2023-11-13 10:54:09 GMT; 2min 57s ago
       Docs: man:interfaces(5)
    Process: 499 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=1/FAILURE)
   Main PID: 499 (code=exited, status=1/FAILURE)
        CPU: 142ms

Nov 13 10:54:09 test-jammyv6 systemd[1]: Starting Raise network interfaces...
Nov 13 10:54:09 test-jammyv6 ifup[574]: RTNETLINK answers: File exists
Nov 13 10:54:09 test-jammyv6 ifup[499]: ifup: failed to bring up be0
Nov 13 10:54:09 test-jammyv6 systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
Nov 13 10:54:09 test-jammyv6 systemd[1]: networking.service: Failed with result 'exit-code'.
Nov 13 10:54:09 test-jammyv6 systemd[1]: Failed to start Raise network interfaces.

我可以使用以下命令修复它:

root@test-jammyv6:~# systemctl status networking.service
× networking.service - Raise network interfaces
     Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2023-11-13 11:00:56 GMT; 35s ago
       Docs: man:interfaces(5)
    Process: 522 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=1/FAILURE)
   Main PID: 522 (code=exited, status=1/FAILURE)
        CPU: 136ms

Nov 13 11:00:56 test-jammyv6 systemd[1]: Starting Raise network interfaces...
Nov 13 11:00:56 test-jammyv6 ifup[573]: RTNETLINK answers: File exists
Nov 13 11:00:56 test-jammyv6 ifup[522]: ifup: failed to bring up be0
Nov 13 11:00:56 test-jammyv6 systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
Nov 13 11:00:56 test-jammyv6 systemd[1]: networking.service: Failed with result 'exit-code'.
Nov 13 11:00:56 test-jammyv6 systemd[1]: Failed to start Raise network interfaces.
root@test-jammyv6:~# modprobe ipv6
root@test-jammyv6:~# ip -6 route add table be default via 0x00:x00:000:0000::1 dev be0
RTNETLINK answers: No route to host
root@test-jammyv6:~# ip -6 route add  default via 0x00:x00:000:0000::1 dev be0
RTNETLINK answers: No route to host
root@test-jammyv6:~# service networking restart
Job for networking.service failed because the control process exited with error code.
See "systemctl status networking.service" and "journalctl -xeu networking.service" for details.
root@test-jammyv6:~# ip addr flush dev be0
root@test-jammyv6:~# service networking restart
root@test-jammyv6:~# systemctl status networking.service
● networking.service - Raise network interfaces
     Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
     Active: active (exited) since Mon 2023-11-13 11:02:07 GMT; 2s ago
       Docs: man:interfaces(5)
    Process: 1035 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=0/SUCCESS)
   Main PID: 1035 (code=exited, status=0/SUCCESS)
      Tasks: 2 (limit: 9440)
     Memory: 688.0K
        CPU: 430ms
     CGroup: /system.slice/networking.service
             ├─1050 /bin/sh -c "sleep 10s && ping -q -c 60 10.0.100.129 > /dev/null 2>&1 || true &"
             └─1052 sleep 10s

Nov 13 11:02:05 test-jammyv6 systemd[1]: Starting Raise network interfaces...
Nov 13 11:02:07 test-jammyv6 ifup[1097]: Waiting for DAD... Done
Nov 13 11:02:07 test-jammyv6 systemd[1]: Finished Raise network interfaces.

如何修复它并使每次重启时都有正确的配置?

答案1

我已修复,inet6正在更新/etc/网络/接口

iface be0 inet6 static
  pre-up modprobe ipv6
  address 0x00:x00:000:0000::4
  netmask 64

  post-up ip -6 route add table be default via 0x00:x00:000:0000::1 dev be0
  post-up ip -6 route add table be 0x00:x00:000:0000::/64 dev be0 proto kernel scope link src 0x00:x00:000:0000::4
  post-up ip -6 rule add prio 10 from 0x00:x00:000:0000::4 lookup be
  pre-down ip -6 rule del from 0x00:x00:000:0000::4 lookup be
  pre-up ip -6 route flush table be || /bin/true
  post-up ip -6 route flush cache
  post-down ip -6 route flush cache

并删除这些文件:

/etc/network/if-up.d/resolved
/etc/network/if-up.d/resolved

相关内容