# 配置静态ip地址
root@simon:~# vim /etc/network/interfaces auto enp4s0 iface enp4s0 inet static address 192.168.11.166 netmask 255.255.255.0 gateway 192.168.11.254
root@simon:~# vim /etc/netplan/50-cloud-init.yaml network: ethernets: enp4s0: addresses: - 192.168.11.166/24 dhcp4: false gateway4: 192.168.11.254 nameservers: addresses: - 8.8.8.8 version: 2
# 配置iptables
使用配置静态ip方式1 可以使用
root@simon:~# vim /etc/network/interfaces ... pre-up iptables-restore < /etc/network/iptables.up.rules post-down iptables-save > /etc/network/iptables.up.rules
root@simon:~# apt-get install iptables-persistent root@simon:~# netfilter-persistent save root@simon:~# netfilter-persistent reload # 生成的配置存储在 /etc/iptables/rules.v4 /etc/iptables/rules.v6
# 配置dns
root@simon:~# sed -i 's/#DNS=/DNS=8.8.8.8/g' /etc/systemd/resolved.conf root@simon:~# systemctl restart systemd-resolved