ubuntu18.04网络配置示例

网卡启动命令及注意事项

    1、注意是用yaml文件,文件路径在/etc/netplan/*.yaml
    2、注意不能用tab键,只能用空格填充
    3、启动命令是 netplan apply

DHCP配置(当dhcp服务器是一台windows可能需要特殊配置)

root@weq:~# cat /usr/share/doc/netplan/examples/dhcp.yaml
network:
  version: 2
  ethernets:
    enp3s0:
      dhcp4: true

root@weq:~# cat /usr/share/doc/netplan/examples/windows_dhcp_server.yaml
network:
  version: 2
  ethernets:
    enp3s0:
      dhcp4: yes
      dhcp-identifier: mac

单网卡单IP&多IP静态配置

root@weq:~# cat /usr/share/doc/netplan/examples/static.yaml
network:
  version: 2
  ethernets:
    enp3s0:
      addresses:
        - 10.10.10.2/24
        - 123.123.123.3/24
      gateway4: 10.10.10.1
      nameservers:
          addresses: [10.10.10.1, 1.1.1.1]

配置4to6

network:
  version: 2
  tunnels:
    he-ipv6:
      mode: sit
      remote: 26.218.21.6
      local: 217.9.9.27
      addresses:
        - "2001:170:17:34e::2/64"
      gateway6: "2001:170:17:34e::1"

单网卡多IP多出口静态路由配置(因为一张NIC你不能写两个gatway4地址)

teway.yaml# cat /usr/share/doc/netplan/examples/static_singlenic_multiip_multigat
network:
  version: 2
  ethernets:
    eno1:
      addresses:
      - 10.0.0.10/24
      - 11.0.0.11/24
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4
      routes:
      - 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

双网卡静态IP配置

root@weq:~# cat /usr/share/doc/netplan/examples/static.yaml
network:
  version: 2
  ethernets:
    enp3s0:
      addresses:
        - 10.10.10.2/24
        - 123.123.123.3/24
      gateway4: 10.10.10.1
      nameservers:
          addresses: [10.10.10.1, 1.1.1.1]
    enp4s0:
      addresses:
        - 192.168.1.30/24

vlan配置

#查看系统是否加载802.1Q模块
[root@weq ~]# lsmod |grep 8021q
8021q                  20475  0 
garp                    7152  1 8021q

root@weq:~# cat /usr/share/doc/netplan/examples/vlan.yaml
network:
  version: 2
  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 ]

桥接配置&bridges配置

root@weq:~# cat /usr/share/doc/netplan/examples/bridge.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: no
  bridges:
    br0:
      dhcp4: yes
      interfaces:
        - enp3s0

桥vlan&bridge_vlan配置

root@weq:~# cat /usr/share/doc/netplan/examples/bridge_vlan.yaml
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

bond配置

root@weq:~# cat /usr/share/doc/netplan/examples/bonding.yaml
network:
  version: 2
  bonds:
    bond0:
      dhcp4: yes
      interfaces:
        - enp3s0
        - enp4s0
      parameters:
        mode: active-backup
        primary: enp3s0

bond路由配置

root@weq:~# cat /usr/share/doc/netplan/examples/bonding_router.yaml
network:
  version: 2
  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

路由策略配置&基于源的路由配置

root@weq:~# cat /usr/share/doc/netplan/examples/source_routing.yaml
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

路由metric配置

root@weq:~# cat /usr/share/doc/netplan/examples/route_metric.yaml
network:
  version: 2
  ethernets:
    enred:
      dhcp4: yes
      dhcp4-overrides:
        route-metric: 100
    engreen:
      dhcp4: yes
      dhcp4-overrides:
        route-metric: 200

IPv6隧道配置(4to6)

root@weq:~# cat /usr/share/doc/netplan/examples/ipv6_tunnel.yaml
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"

无线网络配置

root@weq:~# cat /usr/share/doc/netplan/examples/wireless.yaml
network:
  version: 2
  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认证配置

root@weq:~# cat /usr/share/doc/netplan/examples/wpa_enterprise.yaml
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"
        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"
        open-network:
          auth:
            key-management: none
      dhcp4: yes
声明:本文为原创,作者为 辣条①号,转载时请保留本声明及附带文章链接:https://boke.wsfnk.com/archives/1253.html
微信打赏微信打赏

如果文章对你有帮助,欢迎点击上方按钮打赏作者

最后编辑于:2020/3/8作者: 辣条①号

现在在做什么? 接下来打算做什么? 你的目标什么? 期限还有多少? 进度如何?

暂无评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注