码迷,mamicode.com
首页 > 系统相关 > 详细

ubuntu 17.10 配置静态IP地址

时间:2017-11-20 15:43:54      阅读:7550      评论:0      收藏:0      [点我收藏+]

标签:ubuntu   netplan   

系统安装完成之后默认是动态分配IP

liyaoyi@ubuntu:~$ ifconfig
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.209.221  netmask 255.255.255.0  broadcast 192.168.209.255
        inet6 fe80::20c:29ff:fe9b:2437  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:9b:24:37  txqueuelen 1000  (Ethernet)
        RX packets 632  bytes 78029 (78.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 440  bytes 56139 (56.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 102  bytes 7728 (7.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 102  bytes 7728 (7.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


之前的版本是在/etc/network/interfaces中修改,新版本使用/etc/netplan/*.yaml 

liyaoyi@ubuntu:~$ 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:
    ens32:
      dhcp4: yes

编辑YAML文件配置IP信息

liyaoyi@ubuntu:~$ 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:
    ens32:
      dhcp4: no
      dhcp6: no
      addresses: [192.168.209.221/24]
      gateway4: 192.168.209.2
      nameservers:
        addresses: [8.8.8.8, 114.114.114.114]


执行命令让配置生效:

liyaoyi@ubuntu:~$ sudo netplan apply


显示debug信息

liyaoyi@ubuntu:~$ sudo netplan  --debug  apply 
** (generate:2842): DEBUG: Processing input file //etc/netplan/01-netcfg.yaml..
** (generate:2842): DEBUG: starting new processing pass
** (generate:2842): DEBUG: ens32: setting default backend to 1
** (generate:2842): DEBUG: Generating output files..
** (generate:2842): DEBUG: NetworkManager: definition ens32 is not for us (backend 1)
DEBUG:netplan generated networkd configuration exists, restarting networkd
DEBUG:no netplan generated NM configuration exists
DEBUG:device ens32 operstate is up, not replugging
DEBUG:netplan triggering .link rules for ens32
DEBUG:device lo operstate is unknown, not replugging
DEBUG:netplan triggering .link rules for lo


netplan 其他参数指令:

netplan generate: 执行后使用 /etc/netplan 生成/run/systemd/network/10-netplan-ens32.network


netplan ifupdown-migrate: 尝试从/etc/network/interfaces转换成netplan需要的yaml格式,如果转换成功会禁止使用/etc/network/interfaces




本文出自 “网络收藏夹” 博客,请务必保留此出处http://liyaoyi.blog.51cto.com/442933/1983481

ubuntu 17.10 配置静态IP地址

标签:ubuntu   netplan   

原文地址:http://liyaoyi.blog.51cto.com/442933/1983481

(0)
(2)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!