新出的Ubuntu服务器18.04版本修改了IP地址配置程序, Ubuntu和Debian的软件架构师删除了以前的ifup/ifdown命令和/etc/network/interfaces配置文件, 改为使用/etc/netplan/01-netcfg.yamlsudo netplay apply命令管理IP地址.

这个改动影响了我公司基于Ubuntu 16.04 LTS构建的网关产品的运行环境.
对开发人员来说, 从16.04迁移到18.04会很麻烦.


本文来自以下网址:

  • https://linuxconfig.org/how-to-configure-static-ip-address-on-ubuntu-18-04-bionic-beaver-linux

Ubuntu 18.04 Server

To configure a static IP address on your Ubuntu 18.04 server you need to modify a relevant netplan network configuration file within /etc/netplan/ directory.

For example you might find there a default netplan configuration file called 01-netcfg.yaml or 50-cloud-init.yaml with a following content instructing the networkd deamon to configure your network interface via DHCP:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:version: 2renderer: networkdethernets:enp0s3:dhcp4: yes

To set your network interface enp0s3 to static IP address 192.168.1.222 with gateway 192.168.1.1 and DNS server as 8.8.8.8 and 8.8.4.4 replace the above configuration with the one below.

WARNING:

You must adhere to a correct code indent for each line of the block. In other words the prefix number of spaces for each line is important. Othersiwe you may end up with an error message similar to: Invalid YAML at //etc/netplan/01-netcfg.yaml line 7 column 6: did not find expected key

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:version: 2renderer: networkdethernets:enp0s3:dhcp4: noaddresses: [192.168.1.222/24]gateway4: 192.168.1.1nameservers:addresses: [8.8.8.8,8.8.4.4]

Once ready apply changes with:
$ sudo netplan apply
In case you run into some issues execute:
$ sudo netplan --debug apply


Netplan and systemd-networkd

ifupdown (including the familiar ifup and ifdown utilities) has been replaced by Netplan. Netplan is a simplified interface for configuring Linux networking, where YAML files in /etc/netplan are used to generate configuration information for either NetworkManager or — in the case of new Ubuntu Server installations – systemd-networkd.

The ip link set command is a replacement for ifup and ifdown. You can learn more about it in the How To Configure Network Interfaces and Addresses section of our IPRoute2 Tools tutorial.

For more information on configuring Netplan, see the official documentation. Details on how to use and configure systemd-networkd are available in the systemd-networkd.service and systemd.network man pages.

The command networkctl can output a summary of your network devices:

networkctl
OutputIDX LINK             TYPE               OPERATIONAL SETUP1 lo               loopback           carrier     unmanaged2 eth0             ether              routable    configured

Run the command with the status flag and it will print the state of each IP address on the system:

networkctl status
Output●        State: routableAddress: 192.0.2.10 on eth0203.0.113.241 on eth02001:DB8:68be:caff:fe4c:c963 on eth0Gateway: 203.0.113.1 (ICANN, IANA Department) on eth0DNS: 203.0.113.2203.0.113.3

参考资料: https://www.digital 和 谐 ocean.com/community/tutorials/what-s-new-in-ubuntu-18-04
(访问上述URL请手动删除“和 谐”字样)

Ubuntu 18.04 Server必须使用netplan命令配置IP地址相关推荐

  1. 在Ubuntu 18.04系统中使用Netplan工具配置网络

    Netplan 是一款使用在终端的配置网络工具,本文介绍在 Ubuntu 18.04 系统中使用 Netplan 来配置网络,新的配置文件.网络设备名称.配置静态 IP 地址.测试配置并应用.配置 D ...

  2. Ubuntu 18.04 server配置多用户深度学习服务器

    Ubuntu 18.04 server配置多用户深度学习服务器 1 重装系统 2 安装图形界面 2.1 更改Ubuntu 镜像源 2.2 安装图形界面 2.3安装gcc , make等库 3 安装Nv ...

  3. Ubuntu 18.04 从零开始安装显卡驱动、配置MMDetection3D环境

    Ubuntu 18.04 从零开始安装显卡驱动.配置MMDetection3D环境 概要 安装NVIDIA英伟达显卡驱动 参考文献 其他 安装CUDA 11.3.CuDNN.Anaconda 安装CU ...

  4. ubuntu 启动图形界面命令_Windows 10 远程连接 Ubuntu 18.04 Server图形界面

    目录  0. 环境信息和说明 Ubuntu 18.04上安装xrdp远程ubuntu-desktop桌面服务 Ubuntu 18.04上安装xrdp远程Xfce桌面服务 Ubuntu 18.04上安装 ...

  5. Ubuntu 18.04 Server 设置静态IP

    一.背景 Netplan是Ubuntu 17.10中引入的一种新的命令行网络配置实用程序,用于在Ubuntu系统中轻松管理和配置网络设置.它允许您使用YAML抽象来配置网络接口.它可与NetworkM ...

  6. Ubuntu 18.04环境下Django的安装配置图文详解

    Django介绍 Django是一个免费的开源高级Python Web框架,旨在帮助开发人员构建安全,可扩展和可维护的Web应用程序. 根据您的需要,有不同的方法来安装Django.它可以使用pip在 ...

  7. ubuntu 18.04 server安装CIAO时出现ds9错误的解决办法

    报错如下: ......path-to-ciao/ots/lib/libtinfo.so.5: no version information available ...... 解决办法: 复制libt ...

  8. Ubuntu 18.04安装OpenCV4.0和环境配置

    文章目录 1 安装前准备 1.1 安装依赖 1.2 下载源文件 2 安装过程 3 OpenCV配置环境 3.1 pkg-config环境 3.2 动态库环境 3.3 python-opencv环境 4 ...

  9. linux ifconfig命令配置ip地址

    linxu下网卡命名规律:eth0,eth1. 第一块以太网 第二块lo为环回接口,它的IP地址固定为127.0.0.1,掩码8位.它代表你的机器本身.                  ifconf ...

最新文章

  1. 网校mysql设计规范_点击!2019年9月二级MySQL试题
  2. 五大点,搞懂单线程的Redis到底快在哪里
  3. GitHub Top 100 Objective-C 项目简介
  4. 10 分钟上手 Vim,常用命令大盘点
  5. linux 下添加,修改,删除路由
  6. [react] 装饰器(Decorator)在React中有什么应用?
  7. Linux开发cocos2dx程序环境搭建
  8. ubuntu 16.04 Nginx源码部署安装
  9. python内核死亡的原因_Python xgboost:内核死亡
  10. teststand调用python模块_NI TestStand 2019下载-测试管理软件NI TestStand 2019下载v19.0.1 官方版-西西软件下载...
  11. 元素定位(d4-2)
  12. MySQL 优化技巧
  13. 苹果丽黑字体下载 Hiragino Sans GB W3/W6 ttf格式
  14. PHP医学上什么意思,apache医学上表示什么
  15. MIMO如何获得分集增益(2)
  16. 打造最美HTML5 3D机房(第三季新增资产管理、动环监控)
  17. Solaris adsl上网
  18. 山东法律学校97级二班计算机班,山东法律学校宿舍条件
  19. 微信小程序 获取当前日期时间
  20. google vr学习资料整理

热门文章

  1. master节点重置后添加node报错_企业实战(23)基于Docker平台的Jenkins添加node节点与报错详解(2)...
  2. 管家婆 源码 php,在windows平台上构建本身的PHP
  3. 电脑远程服务_电脑远程维修专家在线服务
  4. 测试类什么时候初始化
  5. vue在个组件中给body加样式,或者给父级组件元素加样式
  6. OpenCV blur和boxFilter (方框型滤波器)
  7. JAVA大数据-Week4-DAY6-JDBC
  8. 我眼中的ASP.NET Core之微服务 (二)
  9. 在 SSD 上使用 btrfs 文件系统的相关优化
  10. mysql的分区技术