我使用带有 2 个 NIC 的 netplan,一个用于 LAN enp0s31f6,一个用于互联网 enp6s0。
首先,我无法让 systemctl 成功启动 iptables。日志中显示可以启动 - 但当我检查时,iptables 没有设置规则:
Apr 27 11:44:31 localhost systemd[1]: Starting iptables...
Apr 27 11:44:31 localhost iptables[1389]: Executing iptables firewall /etc/iptables/iptables.fw
Apr 27 11:44:31 localhost iptables[1389]: Activating firewall
Apr 27 11:44:31 localhost systemd[1]: Started Wait until snapd is fully seeded.
Apr 27 11:44:31 localhost root: Activating firewall
Apr 27 11:44:31 localhost systemd[1]: Started Authorization Manager.
Apr 27 11:44:31 localhost systemd[1]: Started Accounts Service.
Apr 27 11:44:31 localhost iptables[1389]: Interface ppp0 does not exist
Apr 27 11:44:31 localhost root: Interface ppp0 does not exist
Apr 27 11:44:31 localhost iptables[1389]: Finished executing iptables firewall /etc/iptables/iptables.fw
Apr 27 11:44:31 localhost systemd[1]: Started iptables.
启动时还会出现 2 分钟的暂停,并显示消息“启动作业正在运行,等待网络配置”,但实际上应该已经配置好了。
最后一个问题是 networkctl 输出 - 它说其中一个 NIC 仍在“配置”,而我期望它说它已经完成。
根据答案判断Ubuntu Server 18.04 在启动时等待网络,尽管网络正常,我只需在问题上贴块橡皮膏,并使 01-netcfg.yml 中的 NIC 配置成为可选的。
我必须手动启动 iptables - 我不确定为什么 systemctl 声称运行它但却失败了。
这是 networkctl 列表:
adam@gondolin:~$ networkctl list
IDX LINK TYPE OPERATIONAL SETUP
1 lo loopback carrier unmanaged
2 enp6s0 ether routable configured
3 enp0s31f6 ether routable configuring
4 wlp7s0 wlan off unmanaged
5 ppp0 ppp routable unmanaged
5 links listed.
。
adam@gondolin:~$ ifconfig -a
enp0s31f6: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.3 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::10 prefixlen 128 scopeid 0x20<link>
inet6 fe80::e2d5:5eff:fe62:974c prefixlen 64 scopeid 0x20<link>
ether e0:d5:5e:62:97:4c txqueuelen 1000 (Ethernet)
RX packets 9728 bytes 924557 (924.5 KB)
RX errors 0 dropped 59 overruns 0 frame 0
TX packets 485 bytes 106008 (106.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16 memory 0xf7500000-f7520000
enp6s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.2.10 netmask 255.255.255.0 broadcast 192.168.2.255
inet6 fe80::e2d5:5eff:fe62:974e prefixlen 64 scopeid 0x20<link>
ether e0:d5:5e:62:97:4e txqueuelen 1000 (Ethernet)
RX packets 5825 bytes 3847019 (3.8 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4960 bytes 652504 (652.5 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xf7200000-f721ffff
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 479 bytes 61492 (61.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 479 bytes 61492 (61.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ppp0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1472
inet 81.156.25.53 netmask 255.255.255.255 destination 172.16.11.38
ppp txqueuelen 3 (Point-to-Point Protocol)
RX packets 5504 bytes 3691409 (3.6 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4710 bytes 534007 (534.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlp7s0: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 00:e1:8c:75:39:d3 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
01-netcfg.yml:
network:
version: 2
renderer: networkd
ethernets:
enp6s0:
dhcp4: yes
dhcp6: yes
enp0s31f6:
addresses:
- fe80::10/128
- 192.168.0.3/24
dhcp4: yes
dhcp6: yes
这是我的 iptables.service:
adam@gondolin:~$ cat /etc/systemd/system/iptables.service
[Unit]
Description=iptables
StartLimitBurst=5
StartLimitIntervalSec=0
After=ppp.service
Wants=ppp.service
[Service]
ExecStart=/etc/iptables/iptables start
ExecStop=/etc/iptables/iptables stop
Type=oneshot
RemainAfterExit=true
StandardOutput=journal
[Install]
WantedBy=multi-user.target
和 ppp.service
adam@gondolin:~$ cat /etc/systemd/system/ppp.service
[Unit]
Description=PPPoE
#After=network.target
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/usr/bin/pon provider
ExecStop=/usr/bin/poff -a
#Type=notify
[Install]
#WantedBy=multi-user.target
答案1
因为您已将 ppp 服务定义为Type=oneshot
,所以依赖于它的其他服务会立即启动,因此您的 ppp 链路启动和 iptables 运行之间存在竞争。
我不知道如何为 ppp 构建一个 systemd 服务,让它等待链接建立后再继续执行相关服务。