Ubuntu server(18.04.5)的安装优化与常用网络配置

Ubuntu server(18.04.5)的安装优化与常用网络配置

一、Ubuntu server的安装

1、软件环境

1.1Vmware软件

​ 网上已经出现VMware Workstation v16.0.0 中文破解版了,准备把系统备份后再安装,以免机器码变化。

1.2Ubuntu镜像

http://cdimage.ubuntu.com/releases/

关于站点镜像

  • Server install image

    • The server install image allows you to install Ubuntu permanently on a computer for use as a server. It will not install a graphical user interface.
  • Preinstalled server image

    • The preinstalled-server image allows you to unpack a preinstalled version of Ubuntu onto a target device.
  • 带live,ISO镜像提供不安装就可以试用系统的功能;不带live,不可用试用,但是可以直接进行系统安装。

    综合以上因素,选用当前最新的ubuntu-18.04.5-server-amd64镜像。

2、Ubuntu Server安装

​ 按文档安装

3、Ubuntu server的优化

3.1更改主机名

# hostname
dl-homework
# hostnamectl set-hostname dl-homework.linux.com
# hostname
dl-homework.linux.com

3.2 更改网卡名为eth*

# vim /etc/default/grub
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=2
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"

​ 更改GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0",重启系统#reboot,配置生效。如果安装时已经更改这两个参数,则无需调整。

3.3允许root通过ssh远程登录

# vim /etc/ssh/sshd_config
PermitRootLogin yes  #将参数设置成yes
# passwd  #重置root密码,可与原密码相同
# systemctl restart sshd  #重启sshd服务

​ root可以远程登录系统。

3.4Ubuntu软件包管理

​ 可根据下面网站中的提示修改软件源,常用的地址有:

​ 阿里云仓库地址:https://developer.aliyun.com/mirror/

​ 中科大:http://mirrors.ustc.edu.cn/help/ubuntu.html

​ 清华大学:https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/

​ 华为:https://mirrors.huaweicloud.com/

​ 下面同时使用阿里云仓库与华为仓库

#vim /etc/apt/sources.list
# deb cdrom:[Ubuntu-Server 18.04.5 LTS _Bionic Beaver_ - Release amd64 (20200810)]/ bionic main restricted

#deb cdrom:[Ubuntu-Server 18.04.5 LTS _Bionic Beaver_ - Release amd64 (20200810)]/ bionic main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.huaweicloud.com/ubuntu/ bionic main restricted
# deb-src http://mirrors.huaweicloud.com/ubuntu/ bionic main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.huaweicloud.com/ubuntu/ bionic-updates main restricted
# deb-src http://mirrors.huaweicloud.com/ubuntu/ bionic-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirrors.huaweicloud.com/ubuntu/ bionic universe
# deb-src http://mirrors.huaweicloud.com/ubuntu/ bionic universe
deb http://mirrors.huaweicloud.com/ubuntu/ bionic-updates universe
# deb-src http://mirrors.huaweicloud.com/ubuntu/ bionic-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://mirrors.huaweicloud.com/ubuntu/ bionic multiverse
# deb-src http://mirrors.huaweicloud.com/ubuntu/ bionic multiverse
deb http://mirrors.huaweicloud.com/ubuntu/ bionic-updates multiverse
# deb-src http://mirrors.huaweicloud.com/ubuntu/ bionic-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://mirrors.huaweicloud.com/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src http://mirrors.huaweicloud.com/ubuntu/ bionic-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu bionic partner
# deb-src http://archive.canonical.com/ubuntu bionic partner

deb http://mirrors.huaweicloud.com/ubuntu bionic-security main restricted
# deb-src http://mirrors.huaweicloud.com/ubuntu bionic-security main restricted
deb http://mirrors.huaweicloud.com/ubuntu bionic-security universe
# deb-src http://mirrors.huaweicloud.com/ubuntu bionic-security universe
deb http://mirrors.huaweicloud.com/ubuntu bionic-security multiverse
# deb-src http://mirrors.huaweicloud.com/ubuntu bionic-security multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

#apt update

二、Ubuntu server的网卡绑定和桥接

1、Vmware网络

以太网适配器 VMware Network Adapter VMnet1:

连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::74fd:efa6:c03e:428c%18
IPv4 地址 . . . . . . . . . . . . : 10.20.0.1
子网掩码 . . . . . . . . . . . . : 255.255.0.0
默认网关. . . . . . . . . . . . . :

以太网适配器 VMware Network Adapter VMnet8:

连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::84cd:283b:4c72:289b%25
IPv4 地址 . . . . . . . . . . . . : 172.20.200.1
子网掩码 . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . :

Ubuntu server(18.04.5)的安装优化与常用网络配置
Ubuntu server(18.04.5)的安装优化与常用网络配置
Ubuntu server(18.04.5)的安装优化与常用网络配置

2、配置单网卡固定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
      addresses: [172.20.200.138/24]
      gateway4: 172.20.200.2
      nameservers:
        addresses: [172.20.200.2]

# netplan apply

# ping www.baidu.com  #与外网联通
PING www.a.shifen.com (61.135.185.32) 56(84) bytes of data.
64 bytes from 61.135.185.32 (61.135.185.32): icmp_seq=1 ttl=128 time=23.1 ms
64 bytes from 61.135.185.32 (61.135.185.32): icmp_seq=2 ttl=128 time=25.2 ms
64 bytes from 61.135.185.32 (61.135.185.32): icmp_seq=3 ttl=128 time=25.9 ms

3、配置双网卡固定IP地址

3.1虚拟机增加网卡

​ 按操作手册向虚拟机添加新网卡。

3.2编辑网络配置文件

实现效果:网卡eth0配置静态IP 172.20.200.138,能够上外网;网卡eth1配置静态IP 10.20.200.138,能够跟物理主机通信。

root@dl-homework:/etc/apt# ifconfig -a  #虚拟机增加网卡后,查看网卡情况
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.200.138  netmask 255.255.255.0  broadcast 172.20.200.255
        inet6 fe80::20c:29ff:feb3:ce0d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b3:ce:0d  txqueuelen 1000  (Ethernet)
        RX packets 107210  bytes 94648136 (94.6 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 104089  bytes 10956991 (10.9 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 00:0c:29:b3:ce:17  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 180  bytes 15033 (15.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 180  bytes 15033 (15.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
# vim /etc/netplan/01-netcfg.yaml  #设置静态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
      addresses: [172.20.200.138/24]
      gateway4: 172.20.200.2
      nameservers:
        addresses: [172.20.200.2]

    eth1:
      dhcp4: no
      addresses: [10.20.200.138/16]
      routes:
        - to: 172.20.0.0/16
          via: 10.20.0.1    #10.20.0.1模拟核心交换机跨网段传输功能
        - to : 10.20.0.0/16
          via: 10.20.0.1

#netplan apply
root@dl-homework:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.200.138  netmask 255.255.255.0  broadcast 172.20.200.255
        inet6 fe80::20c:29ff:feb3:ce0d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b3:ce:0d  txqueuelen 1000  (Ethernet)
        RX packets 84  bytes 31783 (31.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 92  bytes 8500 (8.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.20.200.138  netmask 255.255.0.0  broadcast 10.20.255.255
        inet6 fe80::20c:29ff:feb3:ce17  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b3:ce:17  txqueuelen 1000  (Ethernet)
        RX packets 58  bytes 7912 (7.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 79  bytes 15876 (15.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 170  bytes 13562 (13.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 170  bytes 13562 (13.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

root@dl-homework:~# ping www.baidu.com  #外网联通
PING www.a.shifen.com (61.135.185.32) 56(84) bytes of data.
64 bytes from 61.135.185.32 (61.135.185.32): icmp_seq=1 ttl=128 time=23.3 ms
64 bytes from 61.135.185.32 (61.135.185.32): icmp_seq=2 ttl=128 time=23.2 ms
64 bytes from 61.135.185.32 (61.135.185.32): icmp_seq=3 ttl=128 time=25.7 ms
root@dl-homework:~# ping 10.20.0.1    #与主机网关联通
PING 10.20.0.1 (10.20.0.1) 56(84) bytes of data.
64 bytes from 10.20.0.1: icmp_seq=1 ttl=128 time=0.464 ms
64 bytes from 10.20.0.1: icmp_seq=2 ttl=128 time=0.851 ms
64 bytes from 10.20.0.1: icmp_seq=3 ttl=128 time=0.460 ms

4、单网卡桥接

# 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
      addresses: [10.20.200.138/16]
      routes:
        - to: 172.20.0.0/16
          via: 10.20.0.1
        - to : 10.20.0.0/16
          via: 10.20.0.1

   bridges:
    br0:
      dhcp4: no
      dhcp6: no
      addresses: [172.20.200.138/24]
      gateway4: 172.20.200.2
      nameservers:
        addresses: [172.20.200.2]
      interfaces:
        - eth0

#netplan apply
root@dl-homework:/etc/netplan# ifconfig  
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.200.138  netmask 255.255.255.0  broadcast 172.20.200.255
        inet6 fe80::7409:97ff:fe03:8c80  prefixlen 64  scopeid 0x20<link>
        ether 76:09:97:03:8c:80  txqueuelen 1000  (Ethernet)
        RX packets 6  bytes 611 (611.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 21  bytes 1682 (1.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:b3:ce:0d  txqueuelen 1000  (Ethernet)
        RX packets 298  bytes 85771 (85.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 256  bytes 21817 (21.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.20.200.138  netmask 255.255.0.0  broadcast 10.20.255.255
        inet6 fe80::20c:29ff:feb3:ce17  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b3:ce:17  txqueuelen 1000  (Ethernet)
        RX packets 1734  bytes 133513 (133.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2780  bytes 331311 (331.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 262  bytes 21697 (21.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 262  bytes 21697 (21.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
root@dl-homework:/etc/netplan# ping www.baidu.com  #与外网联通
PING www.a.shifen.com (61.135.185.32) 56(84) bytes of data.
64 bytes from 61.135.185.32 (61.135.185.32): icmp_seq=1 ttl=128 time=24.8 ms
64 bytes from 61.135.185.32 (61.135.185.32): icmp_seq=2 ttl=128 time=24.0 ms
64 bytes from 61.135.185.32 (61.135.185.32): icmp_seq=3 ttl=128 time=24.3 ms

root@dl-homework:/etc/netplan# ping 10.20.0.1   #与主机网络联通
PING 10.20.0.1 (10.20.0.1) 56(84) bytes of data.
64 bytes from 10.20.0.1: icmp_seq=1 ttl=128 time=0.127 ms
64 bytes from 10.20.0.1: icmp_seq=2 ttl=128 time=0.187 ms

5、双网卡桥接

# 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.200.138/24]
      gateway4: 172.20.200.2
      nameservers:
        addresses: [172.20.200.2]
      interfaces:
        - eth0

    br1:
      dhcp4: no
      dhcp6: no
      addresses: [10.20.200.138/16]
      routes:
        - to: 172.20.0.0/16
          via: 10.20.0.1
        - to : 10.20.0.0/16
          via: 10.20.0.1
      interfaces:
        - eth1

#netplan apply
# ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.200.138  netmask 255.255.255.0  broadcast 172.20.200.255
        inet6 fe80::7409:97ff:fe03:8c80  prefixlen 64  scopeid 0x20<link>
        ether 76:09:97:03:8c:80  txqueuelen 1000  (Ethernet)
        RX packets 112  bytes 14859 (14.8 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 98  bytes 7912 (7.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

br1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.20.200.138  netmask 255.255.0.0  broadcast 10.20.255.255
        inet6 fe80::a01a:d0ff:fe77:146b  prefixlen 64  scopeid 0x20<link>
        ether a2:1a:d0:77:14:6b  txqueuelen 1000  (Ethernet)
        RX packets 23  bytes 1532 (1.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 34  bytes 4208 (4.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:b3:ce:0d  txqueuelen 1000  (Ethernet)
        RX packets 404  bytes 101503 (101.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 332  bytes 28029 (28.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:b3:ce:17  txqueuelen 1000  (Ethernet)
        RX packets 10638  bytes 732110 (732.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 18069  bytes 2119553 (2.1 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 274  bytes 22773 (22.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 274  bytes 22773 (22.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
# ping www.baidu.com
PING www.a.shifen.com (61.135.185.32) 56(84) bytes of data.
64 bytes from 61.135.185.32 (61.135.185.32): icmp_seq=1 ttl=128 time=22.4 ms
64 bytes from 61.135.185.32 (61.135.185.32): icmp_seq=2 ttl=128 time=23.2 ms
# ping 10.20.0.1
PING 10.20.0.1 (10.20.0.1) 56(84) bytes of data.
64 bytes from 10.20.0.1: icmp_seq=1 ttl=128 time=0.469 ms
64 bytes from 10.20.0.1: icmp_seq=2 ttl=128 time=0.557 ms

6、双网卡bond

6.1虚拟机增加网卡

​ 按操作手册向虚拟机添加新网卡,注意此时NAT网络的两个网卡,需要指定为VMnet8。
Ubuntu server(18.04.5)的安装优化与常用网络配置

# ifconfig -a
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.200.138  netmask 255.255.255.0  broadcast 172.20.200.255
        inet6 fe80::7409:97ff:fe03:8c80  prefixlen 64  scopeid 0x20<link>
        ether 76:09:97:03:8c:80  txqueuelen 1000  (Ethernet)
        RX packets 309  bytes 41292 (41.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 173  bytes 13802 (13.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

br1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.20.200.138  netmask 255.255.0.0  broadcast 10.20.255.255
        inet6 fe80::a01a:d0ff:fe77:146b  prefixlen 64  scopeid 0x20<link>
        ether a2:1a:d0:77:14:6b  txqueuelen 1000  (Ethernet)
        RX packets 24439  bytes 1277518 (1.2 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 43309  bytes 5192674 (5.1 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:b3:ce:0d  txqueuelen 1000  (Ethernet)
        RX packets 601  bytes 130694 (130.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 407  bytes 34045 (34.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:b3:ce:17  txqueuelen 1000  (Ethernet)
        RX packets 35054  bytes 2349920 (2.3 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 61344  bytes 7309669 (7.3 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth2: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 00:0c:29:b3:ce:21  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 282  bytes 23445 (23.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 282  bytes 23445 (23.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

6.2编辑配置文件

# 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

  bonds:
    bond0:
      interfaces:
        - eth0
        - eth2
      addresses: [172.20.200.138/24]
      gateway4: 172.20.200.2
      nameservers:
        addresses: [172.20.200.2]
      parameters:
        mode: active-backup
        mii-monitor-interval: 100

  bridges:
    br1:
      dhcp4: no
      dhcp6: no
      addresses: [10.20.200.138/16]
      routes:
        - to: 172.20.0.0/16
          via: 10.20.0.1
        - to : 10.20.0.0/16
          via: 10.20.0.1
      interfaces:
        - eth1

#netplan apply
# ifconfig
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        inet 172.20.200.138  netmask 255.255.255.0  broadcast 172.20.200.255
        inet6 fe80::2ca4:ceff:fea6:2ca5  prefixlen 64  scopeid 0x20<link>
        ether 2e:a4:ce:a6:2c:a5  txqueuelen 1000  (Ethernet)
        RX packets 146  bytes 98130 (98.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 122  bytes 10575 (10.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

br1: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        inet 10.20.200.138  netmask 255.255.0.0  broadcast 10.20.255.255
        inet6 fe80::a01a:d0ff:fe77:146b  prefixlen 64  scopeid 0x20<link>
        ether a2:1a:d0:77:14:6b  txqueuelen 1000  (Ethernet)
        RX packets 712  bytes 56148 (56.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1101  bytes 135906 (135.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 2e:a4:ce:a6:2c:a5  txqueuelen 1000  (Ethernet)
        RX packets 3  bytes 180 (180.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether a2:1a:d0:77:14:6b  txqueuelen 1000  (Ethernet)
        RX packets 712  bytes 56148 (56.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1101  bytes 135906 (135.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth2: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 2e:a4:ce:a6:2c:a5  txqueuelen 1000  (Ethernet)
        RX packets 143  bytes 97950 (97.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 122  bytes 10575 (10.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 20  bytes 1856 (1.8 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 20  bytes 1856 (1.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

# ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=1 ttl=128 time=24.2 ms
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=2 ttl=128 time=22.9 ms
# ping 10.20.0.1
PING 10.20.0.1 (10.20.0.1) 56(84) bytes of data.
64 bytes from 10.20.0.1: icmp_seq=1 ttl=128 time=0.435 ms
64 bytes from 10.20.0.1: icmp_seq=2 ttl=128 time=0.601 ms

7、双网卡bond+网桥

# 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

  bonds:
    bond0:
      interfaces:
        - eth0
        - eth2

      parameters:
        mode: active-backup
        mii-monitor-interval: 100

  bridges:
    br0:
      dhcp4: no
      dhcp6: no
      addresses: [172.20.200.138/24]
      gateway4: 172.20.200.2
      nameservers:
        addresses: [172.20.200.2]
      interfaces:
        - bond0
    br1:
      dhcp4: no
      dhcp6: no
      addresses: [10.20.200.138/16]
      routes:
        - to: 172.20.0.0/16
          via: 10.20.0.1
        - to : 10.20.0.0/16
          via: 10.20.0.1
      interfaces:
        - eth1
#reboot

8、多网卡绑定+桥接

8.1为虚拟机增加网卡

​ 按操作手册添加新网卡,这里再增加一块与VMnet1网络联通的网卡。
Ubuntu server(18.04.5)的安装优化与常用网络配置

# ifconfig -a
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        ether 2e:a4:ce:a6:2c:a5  txqueuelen 1000  (Ethernet)
        RX packets 121  bytes 42316 (42.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 113  bytes 10230 (10.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.200.138  netmask 255.255.255.0  broadcast 172.20.200.255
        inet6 fe80::7409:97ff:fe03:8c80  prefixlen 64  scopeid 0x20<link>
        ether 76:09:97:03:8c:80  txqueuelen 1000  (Ethernet)
        RX packets 110  bytes 40164 (40.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 113  bytes 10008 (10.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

br1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.20.200.138  netmask 255.255.0.0  broadcast 10.20.255.255
        inet6 fe80::a01a:d0ff:fe77:146b  prefixlen 64  scopeid 0x20<link>
        ether a2:1a:d0:77:14:6b  txqueuelen 1000  (Ethernet)
        RX packets 2019  bytes 120662 (120.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3354  bytes 414260 (414.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 2e:a4:ce:a6:2c:a5  txqueuelen 1000  (Ethernet)
        RX packets 3  bytes 180 (180.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:b3:ce:17  txqueuelen 1000  (Ethernet)
        RX packets 2019  bytes 148928 (148.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3354  bytes 414530 (414.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth2: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 2e:a4:ce:a6:2c:a5  txqueuelen 1000  (Ethernet)
        RX packets 118  bytes 42136 (42.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 113  bytes 10230 (10.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth3: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 00:0c:29:b3:ce:2b  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 180  bytes 14498 (14.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 180  bytes 14498 (14.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

8.2编辑配置文件

# 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
        - eth2
      parameters:
        mode: active-backup
        mii-monitor-interval: 100

    bond1:
      interfaces:
        - eth1
        - eth3
      parameters:
        mode: active-backup
        mii-monitor-interval: 100

  bridges:
    br0:
      dhcp4: no
      dhcp6: no
      addresses: [172.20.200.138/24]
      gateway4: 172.20.200.2
      nameservers:
        addresses: [172.20.200.2]
      interfaces:
        - bond0

    br1:
      dhcp4: no
      dhcp6: no
      addresses: [10.20.200.138/16]
      routes:
        - to: 172.20.0.0/16
          via: 10.20.0.1
        - to : 10.20.0.0/16
          via: 10.20.0.1
      interfaces:
        - bond1
        - 
#netplan apply
# ifconfig
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        ether 2e:a4:ce:a6:2c:a5  txqueuelen 1000  (Ethernet)
        RX packets 121  bytes 75192 (75.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 104  bytes 9194 (9.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

bond1: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        ether 1a:f5:c4:b0:b2:34  txqueuelen 1000  (Ethernet)
        RX packets 325  bytes 30554 (30.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 481  bytes 71114 (71.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.200.138  netmask 255.255.255.0  broadcast 172.20.200.255
        inet6 fe80::7409:97ff:fe03:8c80  prefixlen 64  scopeid 0x20<link>
        ether 76:09:97:03:8c:80  txqueuelen 1000  (Ethernet)
        RX packets 101  bytes 72686 (72.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 105  bytes 9080 (9.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

br1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.20.200.138  netmask 255.255.0.0  broadcast 10.20.255.255
        inet6 fe80::a01a:d0ff:fe77:146b  prefixlen 64  scopeid 0x20<link>
        ether a2:1a:d0:77:14:6b  txqueuelen 1000  (Ethernet)
        RX packets 324  bytes 25958 (25.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 481  bytes 70934 (70.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 2e:a4:ce:a6:2c:a5  txqueuelen 1000  (Ethernet)
        RX packets 2  bytes 120 (120.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 1a:f5:c4:b0:b2:34  txqueuelen 1000  (Ethernet)
        RX packets 1  bytes 60 (60.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth2: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 2e:a4:ce:a6:2c:a5  txqueuelen 1000  (Ethernet)
        RX packets 119  bytes 75072 (75.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 104  bytes 9194 (9.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth3: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 1a:f5:c4:b0:b2:34  txqueuelen 1000  (Ethernet)
        RX packets 324  bytes 30494 (30.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 481  bytes 71114 (71.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 30  bytes 2586 (2.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 30  bytes 2586 (2.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
# ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=1 ttl=128 time=24.1 ms
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=2 ttl=128 time=32.8 ms
# ping 10.20.0.1
PING 10.20.0.1 (10.20.0.1) 56(84) bytes of data.
64 bytes from 10.20.0.1: icmp_seq=1 ttl=128 time=0.593 ms
64 bytes from 10.20.0.1: icmp_seq=2 ttl=128 time=0.505 ms

猜你喜欢

转载自blog.51cto.com/12302225/2550872
今日推荐