Ubuntu网络配置-桥接和多网卡绑定

Ubuntu 18.04⽹络配置:
https://netplan.io/ 官⽅⽂档

注: Ubuntu 从 17.10 开始,已放弃在 /etc/network/interfaces ⾥固定IP的配置,⽽是改成 netplan ⽅式,
配置⽂件是:/etc/netplan/01-netcfg.yaml

ubuntu 17.04及之前的静态IP配置⽅式:

# cat /etc/network/interfaces
root@magedu:~# 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

这里和Centos配置文件基本相同,就不在重复赘述,只是配置文件地址有所不同

ubuntu 18.04配置单网卡静态IP地址

#sudo 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.0.18/16]
      gateway4: 172.20.0.1
      nameservers:
         addresses: [223.6.6.6]

# sudo netplan apply

# vim ~/.vimrc #取消vim ⾃动缩进功能
set paste

ubuntu 18.04配置多⽹卡静态IP以及静态路由

# sudo 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.18.3.18/16]
       gateway4: 172.18.0.1
       nameservers:
         addresses: [223.6.6.6]
     eth1:
       dhcp4: no
       dhcp6: no
       addresses: [10.20.3.18/16]
       routes:
         - to: 172.20.0.0/16
           via: 10.20.0.1
         - to: 10.20.0.0/16
           via: 10.20.0.1

# sudo netplan apply

ubuntu 18.04的单⽹卡桥接配置

# sudo cat /etc/netplan/01-netcfg.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: no
      dhcp6: no
  bridges:
    br0:
       dhcp4: no
       dhcp6: no
       addresses: [172.20.20.19/16]
       gateway4: 172.20.0.1
       nameservers:
         addresses: [233.6.6.6, 8.8.8.8, 114.114.114.114]
       interfaces:
         - eth0
  
  # sudo netplan apply

ubuntu 18.04多⽹卡的桥接配置,将br0和br1分别桥接到eth0和eth1。

# sudo cat /etc/netplan/01-netcfg.yaml
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.20.19/16]
       gateway4: 172.20.0.1
       nameservers:
         addresses: [233.6.6.6, 8.8.8.8, 114.114.114.114]
       interfaces:
         - eth0
  bridges:
    br1:
       dhcp4: no
       dhcp6: no
       addresses: [192.168.146.22/24]
       routes:
          - to: 172.20.0.0/16
            via: 192.168.146.2
          - to: 192.168.146.0/24
            via: 192.168.146.2
       interfaces:
         - eth1
         
 # sudo netplan apply 

以上的情景可以满足大多数使用,如需要进一步如提高带宽或做主备等,可使用bond技术

你可能感兴趣的:(Ubuntu)