×

ubuntu 18.04 netplan 配置多网卡、多路由、多ip、bonding

hqy hqy 发表于2024-12-25 16:13:58 浏览37 评论0

抢沙发发表评论

mportant;">Ubuntu 18.04采用Netplan 来管理网络配置,下面说下netplan 多网卡的复杂配置
1.单网卡 DHCP配置

network:version: 2renderer: networkdethernets:enp3s0:dhcp4: true

2.配置静态ip

network:version: 2renderer: networkdethernets:enp3s0:addresses:- 10.10.10.2/24gateway4: 10.10.10.1nameservers:search: [mydomain, otherdomain]addresses: [10.10.10.1, 1.1.1.1]

3.多网口DHCP配置

network:version: 2ethernets:enred:dhcp4: yesdhcp4-overrides:route-metric: 100engreen:dhcp4: yesdhcp4-overrides:route-metric: 200

4.配置无密码的开放wifi

network:version: 2wifis:wl0:access-points:opennetwork: {}dhcp4: yes

5.配置静态地址wifi,使用WAP和WAP2加密的wifi

network:version: 2renderer: networkdwifis:wlp2s0b1:dhcp4: nodhcp6: noaddresses: [192.168.0.21/24]gateway4: 192.168.0.1nameservers:addresses: [192.168.0.1, 8.8.8.8]access-points:"network_ssid_name":password: "**********"

6.一个网口上配置多个地址:

network:version: 2renderer: networkdethernets:enp3s0:addresses:- 10.100.1.38/24- 10.100.1.39/24gateway4: 10.100.1.1

7.一个网口上面有多个地址和多个网关

network:version: 2renderer: networkdethernets:enp3s0:addresses:- 9.0.0.9/24- 10.0.0.10/24- 11.0.0.11/24#gateway4:  # unset, since we configure routes belowroutes:- 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 #优先级

8.bonding 主备模式

network:version: 2renderer: networkdbonds:bond0:dhcp4: yesinterfaces:- enp3s0- enp4s0parameters:mode: active-backupprimary: enp3s0

9.bonding 802.3ad模式

network:version: 2renderer: networkdethernets:enp2s0:dhcp4: noenp3s0:dhcp4: nooptional: truebonds:bond-lan:interfaces: [enp2s0, enp3s0]addresses: [192.168.93.2/24]parameters:mode: 802.3admii-monitor-interval: 1

交换机配置 以华为交换机为例


<Quidway> system-view

[SwitchA] interface eth-trunk 1

[SwitchA-Eth-Trunk1] bpdu enable

[SwitchA-Eth-Trunk1] mode lacp-static

[SwitchA-Eth-Trunk1] q



[SwitchA] interface gigabitethernet 0/0/1

[SwitchA-GigabitEthernet0/0/1] eth-trunk 1

[SwitchA-GigabitEthernet0/0/1] quit

[SwitchA] interface gigabitethernet 0/0/2

[SwitchA-GigabitEthernet0/0/2] eth-trunk 1

[SwitchA-GigabitEthernet0/0/2] q

[SwitchA] display eth-trunk 1 #查看是否协商成功

服务器 cat /proc/net/bonding/bond4-lan #查看是否协商成功

  1. 单网口 多网段 接交换机truk口 打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: [ "114.114.114.114" ]
  1. 配置多网卡多网口多ip多路由

network:version: 2renderer: networkdethernets:ens3:addresses:- 192.168.3.30/24dhcp4: noroutes:- to: 192.168.3.0/24via: 192.168.3.1table: 101routing-policy:- from: 192.168.3.0/24table: 101ens5:addresses:- 192.168.5.24/24dhcp4: nogateway4: 192.168.5.1routes:- to: 192.168.5.0/24via: 192.168.5.1table: 102routing-policy:- from: 192.168.5.0/24table: 102

network:

ethernets:

ens33:

dhcp4: false

dhcp6: false

addresses: [192.168.1.20/24]

#gateway4: 192.168.1.253

routes:

- to: 192.168.0.0/24

via: 192.168.1.253



- to: 192.168.1.0/24

via: 192.168.1.253



- to: 192.168.2.0/24

via: 192.168.1.253



- to: 192.168.3.0/24

via: 192.168.1.253



- to: 192.168.4.0/24

via: 192.168.1.253



- to: 192.168.5.0/24

via: 192.168.1.253



table: 101



routing-policy:

- from: 0.0.0.0/24

table: 101

nameservers:

addresses: [192.168.1.1, 192.168.1.2]

ens34:

dhcp4: false

dhcp6: false

addresses: [172.16.0.10/24]

gateway4: 172.16.0.253

nameservers:

addresses: [172.16.0.1, 192.168.1.1]

version: 2


打赏

本文链接:https://www.kinber.cn/post/4359.html 转载需授权!

分享到:


推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

 您阅读本篇文章共花了: 

群贤毕至

访客