Ubuntu 24.04和Ubuntu 22.04
server和desktop版本yaml名字有点区别,但都在/etc/netplan下并只有一个文件
desktop版本配置的时候需要将renderer: NetworkManager删除
配置里面eth0,eth1就是网卡名,可用指令ip a查看
vi /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
eth0:
# dhcp4和6分别表示是否开启ipv4或ipv6的dhcp自动分配ip
dhcp4: false
dhcp6: false
addresses: [192.168.20.1/24]
eth1:
dhcp4: false
dhcp6: false
# 设置ip和掩码,可以多ip,例如[192.168.0.100/24,192.168.1.100/24]
addresses: [192.168.0.100/24]
# 设置路由网关,比早期版本更灵活,详细用法参考系统相关文档
routes:
- to: default
via: 192.168.0.1
# 设置dns,可以多个
nameservers:
addresses:
- 192.168.0.1
- 192.168.0.2
version: 2
# 修改后应用
netplan apply
Ubuntu 20.04和Ubuntu 18.04
配合和和24.04|22.04主体相同,差别是路由网关部分
vi /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
eth0:
dhcp4: false
dhcp6: false
addresses: [192.168.10.101/24]
eth1:
dhcp4: false
dhcp6: false
addresses: [192.168.0.81/24]
# ipv4网关设置,ipv6设置用gateway6
gateway4: 192.168.0.2
# dns设置格式其实和22.04b版本没区别,yaml格式的不同的数组写法
nameservers:
addresses: [114.114.114.114, 8.8.8.8]
version: 2
# 修改后应用
netplan apply
Ubuntu 16.04
这个和redhat/centos的比较类似
# 网卡设置静态地址
vi /etc/network/interfaces
iface eth0 inet static
address xxx.xxx.xxx.xxx #IP地址
netmask xxx.xxx.xxx.xxx #子网掩码
gateway xxx.xxx.xxx.xxx #网关
# dns
vi /etc/resolv.conf
nameserver 172.16.3.4
# 修改后应用
service networking restart