Ubuntu 20 Netplan 配置网络
- 环回配置
- 网卡配置
- dhcp获取地址
- 静态ip地址,网关,dns
- 桥接网卡
- 网卡绑定 Bond
- 单网卡配置多个ip地址,网关
- 无线网卡连接
- 连接不加密网络
- 连接WPA加密网络,静态IP
- 连接WPA加密网络,动态IP
- 证书认证加密网络
- 高级配置
- 静态路由及开销
- 多网卡绑定,option:true,不等待网卡激活,启动bond
- 桥接网络,并打上VLAN标记
- 配置多个VLAN
- 配置IPV6
- 路由策略
- 隧道模式
- SR-IOV 子网卡(网卡虚拟化)
配置文件 /etc/netplan/00-installer-config.yaml
环回配置
network:
version: 2
renderer: networkd
ethernets:
lo:
match:
name: lo
addresses: [ 127.0.0.1/32 ]
掩码:
32表示32个1,即255.255.255.255
24表示24个1,即255.255.255.0
20表示20个1,即255.255.240.0
网卡配置
dhcp获取地址
network:
ethernets:
ens3:
dhcp4: yes
dhcp4-overrides:
route-metric: 100
ens4:
dhcp4: yes
dhcp4-overrides:
route-metric: 200
version: 2
yes/no 或者 true/false
静态ip地址,网关,dns
network:
renderer: networkd
ethernets:
enp3s0:
addresses:
- 10.10.10.2/24
gateway4: 10.10.10.1
nameservers:
search: [mydomain, otherdomain]
addresses: [10.10.10.1, 1.1.1.1]
version: 2
桥接网卡
network:
version: 2
renderer: networkd
ethernets:
enp3s0:
dhcp4: no
bridges:
br0:
dhcp4: yes
interfaces:
- enp3s0
- enp3s1
网卡绑定 Bond
network:
version: 2
renderer: networkd
ethernets:
enp3s0:
dhcp4: no
bridges:
br0:
dhcp4: yes
interfaces:
- enp3s0
- enp3s1
# 可选向,备份模式
parameters:
mode: active-backup
primary: enp3s0
单网卡配置多个ip地址,网关
network:
version: 2
renderer: networkd
ethernets:
enp3s0:
addresses:
- 10.100.1.38/24
- 10.100.1.39/24
gateway4: 10.100.1.1
无线网卡连接
连接不加密网络
network:
version: 2
wifis:
wl0:
access-points:
opennetwork: {SSID}
dhcp4: yes
连接WPA加密网络,静态IP
network:
version: 2
renderer: networkd
wifis:
wlp2s0b1:
dhcp4: no
dhcp6: no
addresses: [192.168.0.21/24]
gateway4: 192.168.0.1
nameservers:
addresses: [192.168.0.1, 8.8.8.8]
access-points:
"network_ssid_name":
password: "**********"
连接WPA加密网络,动态IP
network:
version: 2
wifis:
wl0:
access-points:
workplace:
auth:
key-management: eap
method: ttls
anonymous-identity: "@internal.example.com"
identity: "joe@internal.example.com"
password: "v3ryS3kr1t"
dhcp4: yes
证书认证加密网络
network:
version: 2
wifis:
wl0:
access-points:
university:
auth:
key-management: eap
method: tls
anonymous-identity: "@cust.example.com"
identity: "cert-joe@cust.example.com"
ca-certificate: /etc/ssl/cust-cacrt.pem
client-certificate: /etc/ssl/cust-crt.pem
client-key: /etc/ssl/cust-key.pem
client-key-password: "d3cryptPr1v4t3K3y"
dhcp4: yes
高级配置
静态路由及开销
network:
version: 2
renderer: networkd
ethernets:
enp3s0:
addresses:
- 9.0.0.9/24
- 10.0.0.10/24
- 11.0.0.11/24
#gateway4: # unset, since we configure routes below
routes:
- to: 0.0.0.0/0
via: 9.0.0.1
metric: 100
- to: 0.0.0.0/0
via: 10.0.0.1
metric: 100
- to: 0.0.0.0/0
via: 11.0.0.1
metric: 100
## NetworkManager作为后端管理服务
network:
version: 2
renderer: NetworkManager
多网卡绑定,option:true,不等待网卡激活,启动bond
network:
version: 2
renderer: networkd
ethernets:
enp1s0:
dhcp4: no
enp2s0:
dhcp4: no
enp3s0:
dhcp4: no
optional: true
enp4s0:
dhcp4: no
optional: true
enp5s0:
dhcp4: no
optional: true
enp6s0:
dhcp4: no
optional: true
bonds:
bond-lan:
interfaces: [enp2s0, enp3s0]
addresses: [192.168.93.2/24]
parameters:
mode: 802.3ad
mii-monitor-interval: 1
bond-wan:
interfaces: [enp1s0, enp4s0]
addresses: [192.168.1.252/24]
gateway4: 192.168.1.1
nameservers:
search: [local]
addresses: [8.8.8.8, 8.8.4.4]
parameters:
mode: active-backup
mii-monitor-interval: 1
gratuitious-arp: 5
bond-conntrack:
interfaces: [enp5s0, enp6s0]
addresses: [192.168.254.2/24]
parameters:
mode: balance-rr
mii-monitor-interval: 1
桥接网络,并打上VLAN标记
network:
version: 2
renderer: networkd
ethernets:
enp0s25:
dhcp4: true
bridges:
br0:
addresses: [ 10.3.99.25/24 ]
interfaces: [ vlan15 ]
vlans:
vlan15:
accept-ra: no
id: 15
link: enp0s25
配置多个VLAN
network:
version: 2
renderer: networkd
ethernets:
mainif:
match:
macaddress: "de:ad:be:ef:ca:fe"
set-name: mainif
addresses: [ "10.3.0.5/23" ]
gateway4: 10.3.0.1
nameservers:
addresses: [ "8.8.8.8", "8.8.4.4" ]
search: [ example.com ]
vlans:
vlan15:
id: 15
link: mainif
addresses: [ "10.3.99.5/24" ]
vlan10:
id: 10
link: mainif
addresses: [ "10.3.98.5/24" ]
nameservers:
addresses: [ "127.0.0.1" ]
search: [ domain1.example.com, domain2.example.com ]
配置IPV6
network:
version: 2
renderer: networkd
ethernets:
addresses: [ "2001:cafe:face:beef::dead:dead/64" ]
routes:
- to: "2001:cafe:face::1/128"
scope: link
- to: "::/0"
via: "2001:cafe:face::1"
on-link: true
路由策略
network:
version: 2
renderer: networkd
ethernets:
ens3:
addresses:
- 192.168.3.30/24
dhcp4: no
routes:
- to: 192.168.3.0/24
via: 192.168.3.1
table: 101
routing-policy:
- from: 192.168.3.0/24
table: 101
ens5:
addresses:
- 192.168.5.24/24
dhcp4: no
gateway4: 192.168.5.1
routes:
- to: 192.168.5.0/24
via: 192.168.5.1
table: 102
routing-policy:
- from: 192.168.5.0/24
table: 102
隧道模式
network:
version: 2
ethernets:
eth0:
addresses:
- 1.1.1.1/24
- "2001:cafe:face::1/64"
gateway4: 1.1.1.254
tunnels:
he-ipv6:
mode: sit
remote: 2.2.2.2
local: 1.1.1.1
addresses:
- "2001:dead:beef::2/64"
gateway6: "2001:dead:beef::1"
SR-IOV 子网卡(网卡虚拟化)
network:
version: 2
ethernets:
eno1:
mtu: 9000
enp1s16f1:
link: eno1
addresses : [ "10.15.98.25/24" ]
vf1:
match:
name: enp1s16f[2-3]
link: eno1
addresses : [ "10.15.99.25/24" ]
发表评论 取消回复