Ubuntu ⽹络配置
文章目录
ubuntu 17.04及之前的静态IP配置⽅式
Ubuntu 从 17.10 开始,已放弃在 /etc/network/interfaces ⾥固定IP的配置,⽽是改成 netplan ⽅式,
配置⽂件是:/etc/netplan/01-netcfg.yaml
//查看配置文件
cat /etc/network/interfaces
---------------------------------
//配置文件内容如下
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto eth0 #⽹卡⾃启动,写⾃⼰要配置IP的实际⽹卡名称
iface eth0 inet static #配置静态IP,写⾃⼰要配置IP的实际⽹卡名称
address 172.18.3.12 #IP地址
netmask 255.255.0.0 #掩码
gateway 172.18.0.1 #⽹关
dns-nameservers 223.6.6.6 #DNS
dns-nameservers 223.5.5.5
------------------------------
//重启⽹络服务
/etc/init.d/networking restart
systemctl restart networking.service
ubuntu 18.04配置静态IP地址
//编辑配置文件
vim /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:
eth0:
dhcp4: no
dhcp6: no
addresses: [ 172.20.26.104/16]
gateway4: 172.20.0.1
nameservers:
addresses: [ 233.6.6.6,180.76.76.76 ]
-------------------------------------------
//重新加载网卡配置文件
sudo netplan apply
ubuntu 18.04配置多⽹卡静态IP以及静态路由
//编辑配置文件
vim /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:
eth0:
dhcp4: no
dhcp6: no
addresses: [ 172.20.26.104/16]
gateway4: 172.20.0.1
nameservers:
addresses: [ 233.6.6.6,180.76.76.76 ]
eth1:
dhcp4: no
dhcp6: no
addresses: [10.20.26.104/16]
routes:
- to: 172.20.0.0/16
via: 10.20.0.1
- to: 10.20.0.0/16
via: 10.20.0.1
- to: 10.2.0.0/16
via: 10.20.0.1
- to: 10.8.0.0/16
via: 10.20.0.1
---------------------------
//重新加载网卡配置文件
sudo netplan apply
ubuntu 18.04的单⽹卡桥接配置
//编辑配置文件
vim /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:
eth0:
dhcp4: no
dhcp6: no
bridges:
br0:
dhcp4: no
dhcp6: no
addresses: [172.20.26.104/16]
gateway4: 172.20.0.1
nameservers:
addresses: [180.76.76.76]
interfaces:
- eth0
--------------------------------------------
//重新加载网卡配置文件
sudo netplan apply
ubuntu 18.04多⽹卡的桥接配置,将br0和br1分别桥接到eth0和eth1
//编辑配置文件
vim /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:
eth0:
dhcp4: no
dhcp6: no
eth1:
dhcp4: no
dhcp6: no
bridges:
br0:
dhcp4: no
dhcp6: no
addresses: [172.20.26.104/16]
gateway4: 172.20.0.1
nameservers:
addresses: [180.76.76.76]
interfaces:
- eth0
br1:
dhcp4: no
dhcp6: no
addresses: [10.20.26.104/16]
routes:
- to: 172.20.0.0/16
via: 10.20.0.1
- to: 10.20.0.0/16
via: 10.20.0.1
- to: 10.2.0.0/16
via: 10.20.0.1
- to: 10.8.0.0/16
via: 10.20.0.1
interfaces:
- eth1
--------------------------------------------
//重新加载网卡配置文件
sudo netplan apply
ubuntu 18.04的双⽹卡绑定配置
//编辑配置文件
vim /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:
eth0:
dhcp4: no
dhcp6: no
eth1:
dhcp4: no
dhcp6: no
bonds:
bond0:
interfaces:
- eth0
- eth1
addresses: [172.20.26.104/16]
gateway4: 172.20.0.1
nameservers:
addresses: [180.76.76.76]
parameters:
mode: active-backup
mii-monitor-interval: 100
--------------------------------------------
//重新加载网卡配置文件
sudo netplan apply
//重启,才能生效
reboot
//查看bond0工作状态信息
root@bj-magedu-v-study-104:~# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:78:19:34
Slave queue ID: 0
Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:78:19:2a
Slave queue ID: 0
双网卡绑定Bond模式
七种bond模式说明:
- 第⼀种模式:mod=0,即:(balance-rr) Round-robin policy(平衡抡循环策略)
特点:- 传输数据包顺序是依次传输(即:第1个包⾛eth0,下⼀个包就⾛eth1….⼀直循环下去,直到最后⼀个传输完毕),
- 此模式提供负载平衡和容错能⼒。
- 第⼆种模式:mod=1,即: (active-backup) Active-backup policy(主-备份策略)
特点:- 只有⼀个设备处于活动状态,当⼀个宕掉另⼀个⻢上由备份转换为主设备。
- mac地址是外部可⻅得,从外⾯看来,bond的MAC地址是唯⼀的,以避免switch(交换机)发⽣混乱。
- 此模式只提供了容错能⼒;由此可⻅此算法的优点是可以提供⾼⽹络连接的可⽤性,
- 但是它的资源利⽤率较低,只有⼀个接⼝处于⼯作状态,在有 N 个⽹络接⼝的情况下,资源利⽤率为1/N。
- 第三种模式:mod=2,即:(balance-xor) XOR policy(平衡策略)
特点:- 基于指定的传输HASH策略传输数据包。缺省的策略是:(源MAC地址 XOR ⽬标MAC地址) % slave数量。
- 其他的传输策略可以通过xmit_hash_policy选项指定,
- 此模式提供负载平衡和容错能⼒。
- 第四种模式:mod=3,即:broadcast(⼴播策略)
特点:- 在每个slave接⼝上传输每个数据包,此模式提供了容错能⼒。
- 第五种模式:mod=4,即:(802.3ad) IEEE 802.3adDynamic link aggregation(IEEE 802.3ad 动态链接聚合)
特点:- 创建⼀个聚合组,它们共享同样的速率和双⼯设定。
- 根据802.3ad规范将多个slave⼯作在同⼀个激活的聚合体下。
- 必要条件:
条件1:ethtool⽀持获取每个slave的速率和双⼯设定。
条件2:switch(交换机)⽀持IEEE 802.3ad Dynamic link aggregation。
条件3:⼤多数switch(交换机)需要经过特定配置才能⽀持802.3ad模式。
- 第六种模式:mod=5,即:(balance-tlb) Adaptive transmit load balancing(适配器传输负载均衡)
特点:- 不需要任何特别的switch(交换机)⽀持的通道bonding。
- 在每个slave上根据当前的负载(根据速度计算)分配外出流量。如果正在接受数据的slave出故障了,另⼀个slave接管失败的slave的MAC地址。
- 该模式的必要条件:
ethtool⽀持获取每个slave的速率
- 第七种模式:mod=6,即:(balance-alb) Adaptive load balancing(适配器适应性负载均衡)
特点:- 该模式包含了balance-tlb模式,同时加上针对IPV4流量的接收负载均衡(receive load balance,rlb)
- ⽽且不需要任何switch(交换机)的⽀持
双⽹卡绑定+桥接
⽹卡绑定⽤于提供⽹卡接⼝冗余以及⾼可⽤和端⼝聚合功能,桥接⽹卡再给需要桥接设备的服务使⽤。
//编辑配置文件
vim /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:
eth0:
dhcp4: no
dhcp6: no
eth1:
dhcp4: no
dhcp6: no
bonds:
bond0:
interfaces:
- eth0
- eth1
addresses: [172.20.26.104/16]
gateway4: 172.20.0.1
nameservers:
addresses: [180.76.76.76]
parameters:
mode: active-backup
mii-monitor-interval: 100
bridges:
br0:
dhcp4: no
dhcp6: no
addresses: [172.20.26.104/16]
gateway4: 172.20.0.1
nameservers:
addresses: [180.76.76.76]
interfaces:
- bond0
--------------------------------------------
//重新加载网卡配置文件
sudo netplan apply
//重启,才能生效
reboot
//查看bond0工作状态信息
root@bj-magedu-v-study-104:~# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:78:19:34
Slave queue ID: 0
Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:78:19:2a
Slave queue ID: 0
内外多网卡绑定
多网络情况下实现网卡绑定
//编辑配置文件
vim /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:
eth0:
dhcp4: no
dhcp6: no
eth1:
dhcp4: no
dhcp6: no
eth2:
dhcp4: no
dhcp6: no
eth3:
dhcp4: no
dhcp6: no
bonds:
bond0:
interfaces:
- eth0
- eth1
addresses: [172.20.26.104/16]
gateway4: 172.20.0.1
nameservers:
addresses: [180.76.76.76]
parameters:
mode: active-backup
mii-monitor-interval: 100
bond1:
interfaces:
- eth2
- eth3
addresses: [10.20.26.104/16]
gateway4: 172.20.0.1
nameservers:
addresses: [180.76.76.76]
parameters:
mode: active-backup
mii-monitor-interval: 100
--------------------------------------------
//重新加载网卡配置文件
sudo netplan apply
//重启,才能生效
reboot
内⽹多⽹卡绑定+桥接
//编辑配置文件
vim /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:
eth0:
dhcp4: no
dhcp6: no
eth1:
dhcp4: no
dhcp6: no
eth2:
dhcp4: no
dhcp6: no
eth3:
dhcp4: no
dhcp6: no
bonds:
bond0:
interfaces:
- eth0
- eth1
parameters:
mode: active-backup
mii-monitor-interval: 100
bond1:
interfaces:
- eth2
- eth3
parameters:
mode: active-backup
mii-monitor-interval: 100
bridges:
br0:
dhcp4: no
dhcp6: no
addresses: [172.20.26.104/16]
gateway4: 172.20.0.1
nameservers:
addresses: [180.76.76.76]
interfaces:
- bond0
br1:
dhcp4: no
dhcp6: no
addresses: [10.20.26.104/16]
gateway4: 172.20.0.1
nameservers:
addresses: [180.76.76.76]
interfaces:
- bond1
routes:
- to: 172.20.0.0/16
via: 10.20.0.1
- to: 10.20.0.0/16
via: 10.20.0.1
- to: 10.2.0.0/16
via: 10.20.0.1
- to: 10.8.0.0/16
via: 10.20.0.1
--------------------------------------------
//重新加载网卡配置文件
sudo netplan apply
//重启,才能生效
reboot
来源:CSDN
作者:Nanjing_bokebi
链接:https://blog.csdn.net/Nanjing_bokebi/article/details/103754783