UBUNTU网卡配置
主机名修改
hostnamectl set-hostname ubuntu1804
cat /etc/hostname
网卡改名
#修改配置文件为下面形式
vi /etc/default/grub
GRUB_CMDLINE_LINUX="net.ifnames=0"
#生效新的grub.cfg文件
grub-mkconfig -o /boot/grub/grub.cfg
#或者
update-grub
#重启生效
reboot
修改名称后需要修改配置文件否则没有地址(一般两个缩进)
cat /etc/netplan/01-netcfg.yaml #自动获取
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: yes
修改后执行
netplan apply命令生效
添加网卡后 配置静态地址
yuml格式尽量用空格缩进
[root@ubuntu1804||15|netplan]#cd /etc/netplan/
[root@ubuntu1804||16|netplan]#ls
01-netcfg.yaml
[root@ubuntu1804||17|netplan]#cp 01-netcfg.yaml 02-netcfg.yaml
[root@ubuntu1804||18|netplan]#vim 02-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth1:
dhcp4: no #自动获取
addresses: [192.168.8.10/24,10.0.0.10/8] #两个地址
gateway4: 10.0.0.3 #网关
nameservers:
search: [magedu.com, magedu.org] #自动补全
addresses: [180.76.76.76, 8.8.8.8, 1.1.1.1] #DNS
百度
netplan apply #重启网络服务
查看ip和gateway
root@ubuntu1804:~#ip addr
root@ubuntu1804:~#route -n
查看DNS
root@ubuntu1804:~#ls -l /etc/resolv.conf
lrwxrwxrwx 1 root root 39 Dec 12 11:36 /etc/resolv.conf ->
…/run/systemd/resolve/stub-resolv.conf
root@ubuntu1804:~#systemd-resolve --status #观察DNS信息
配置多卡静态IP #可以用一个文件代替多个
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
dhcp6: no
addresses: [10.0.0.18/16]
gateway4: 10.0.0.2 网关
nameservers:
addresses: [223.6.6.6] DNS
eth1:
dhcp4: no
dhcp6: no
addresses: [10.20.0.18/16]
routes: #配置路由
- to: 10.30.0.0/16 #到达哪个网段
via: 10.20.0.1 #网关(指向)
- to: 10.40.0.0/16
via: 10.20.0.1
- to: 10.50.0.0/16
via: 10.20.0.1
- to: 10.60.0.0/16
via: 10.20.0.1
netplan aply 生效
route -n 查看
单网卡桥接
3 4 网卡桥接
[root@ubuntu1804||34|netplan]#cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth1:
dhcp4: no
dhcp6: no
eth2:
dhcp4: no
bridges: #单独列出
br0: #设备名
dhcp4: no
dhcp6: no
addresses: [10.0.0.18/16]
gateway4: 10.0.0.1
nameservers:
addresses: [223.6.6.6]
interfaces:
- eth1 #要桥接的网卡
- eth2
netplan apply #生效
brctl show
ifconfig br0
四块网卡桥接
两个桥接
network:
version: 2
renderer: networkd
ethernets:
eth1:
dhcp4: no
dhcp6: no
eth2:
dhcp4: no
eth3:
dhcp4: no
dhcp6: no
eth4:
dhcp4: no
bridges:
br0:
dhcp4: no
dhcp6: no
addresses: [10.0.0.18/16]
gateway4: 10.0.0.1
nameservers:
addresses: [223.6.6.6]
interfaces:
- eth1 #要桥接的网卡
- eth2
br1:
dhcp4: no
dhcp6: no
addresses: [10.0.0.18/16]
gateway4: 10.0.0.1
nameservers:
addresses: [223.6.6.6]
interfaces:
- eth3 #要桥接的网卡
- eth4
brctl stp br1 off #生成树协议
ifconfig br1 down
brctl delbr br1 #删除
多网卡绑定
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
dhcp6: no
eth1:
dhcp4: no
dhcp6: no
bonds:
bond0:
interfaces:
- eth3
- eth4
addresses: [172.160.18/16]
gateway4: 172.16.0.1
nameservers:
addresses: