zoukankan      html  css  js  c++  java
  • ubuntu网卡配置

    网卡配置文件采用YAML格式,必须以 /etc/netplan/XXX.yaml 文件命名方式存放
    可以每个网卡对应一个单独的配置文件,也可以将所有网卡都放在一个配置文件里

    自动获取IP

    root@ubuntu1804:~# cat /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: yes
    
    # 修改网卡配置文件后需执行命令生效:
    root@ubuntu1804:~#netplan apply
    

    配置静态IP

    root@ubuntu1804:~#vim /etc/netplan/01-netcfg.yaml
    network:
      version: 2
      renderer: networkd
    ethernets:
      eth0:
        dhcp4: no
        addresses: [192.168.8.10/24,10.0.0.10/8]  #或者用下面两行,两种格式不能混用
        - 192.168.8.10/24
        - 10.0.0.10/8
        gateway4: 10.0.0.2
        nameservers:
        search: [baidu.com, google.org]
          addresses: [114.114.114.114, 8.8.8.8, 1.1.1.1]
    

    image

    配置多网卡静态IP和静态路由

    root@ubuntu1804:~#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: [10.0.0.100/16]
          gateway4: 10.0.0.2
          nameservers:
            addresses: [223.6.6.6]
        eth1:
          dhcp4: no
          dhcp6: no 
          addresses: [10.20.0.100/16]
          routes:
         - to: 10.30.0.0/16
           via: 10.20.0.1
         - to: 10.40.0.0/16
         via: 10.20.0.1
         - to: 10.50.0.0/16
         via: 10.20.0.1
         - to: 10.60.0.0/16
         via: 10.20.0.1
    
    root@ubuntu1804:~#netplan apply
    root@ubuntu1804:~#route -n
    Kernel IP routing table
    Destination   Gateway     Genmask     Flags Metric Ref  Use Iface
    0.0.0.0     10.0.0.2     0.0.0.0     UG   0    0     0 eth0
    10.0.0.0     0.0.0.0     255.255.0.0   U   0    0     0 eth0
    10.20.0.0    0.0.0.0     255.255.0.0   U   0    0     0 eth1
    10.30.0.0    10.20.0.1    255.255.0.0   UG   0    0     0 eth1
    10.40.0.0    10.20.0.1    255.255.0.0   UG   0    0     0 eth1
    10.50.0.0    10.20.0.1    255.255.0.0   UG   0    0     0 eth1
    10.60.0.0    10.20.0.1    255.255.0.0   UG   0    0     0 eth1
    
  • 相关阅读:
    POJ3783Balls[DP 最坏情况最优解]
    openjudge2989糖果[DP 01背包可行性]
    POJ1160 Post Office[序列DP]
    石子合并[DP-N3]
    POJ1065Wooden Sticks[DP LIS]
    POJ3636Nested Dolls[DP LIS]
    LCIS(最长公共上升子序列)Vijos1264神秘的咒语
    Vijos1680距离/openjudge2988计算字符串的距离[DP]
    Vijos1392拼拼图的小衫[背包DP|二维信息DP]
    NOIP2000方格取数[DP]
  • 原文地址:https://www.cnblogs.com/firewalld/p/14666976.html
Copyright © 2011-2022 走看看