如何在 Ubuntu18.04 server 服务器版本的操作系统下 配置IP


如题,现有需求,为一个server版本的Ubuntu18.04配置 IP 。

 

 

在网上查到了     Ubuntu18.04  桌面版本  的配置方法:

https://www.cnblogs.com/sammei/p/ubuntu-dan-wang-ka-shuang-ip.html

 

 

 

$ cat  /etc/network/interfaces

 

 

 

修改配置文件:

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback


auto eth0
iface eth0 inet static
address 192.168.1.111
gateway 192.168.1.1
netmask 255.255.255.0


auto eth0:1
iface eth0:1 inet dhcp

 

 

 

 

启用对网卡  eth0  的新IP配置:

sudo ifup eth0:1

 

 

==============================================

 

 18.04 server 版本:

 

 

给一个网卡配置两个固定IP:

http://www.shadowindy.com/wordpress/index.php/2019/10/22/123/

 

配置网卡文件 /etc/netplan/50-cloud-init.yaml 

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        eth0:
                addresses: [192.168.100.100/24,172.18.139.54/24]
                gateway4: 192.168.100.1
                dhcp4: no
    version: 2  

 

 

 

=================================

 

 

 

给一个网卡配置一个IP:

 

 

 

 

 

 

 

 

 

 

 

===================================

 

 

重启网络:

sudo netplan apply

 

 

 

 

===============================

使用 netplan 配置网络时需要注意:

1.  只能使用空格,不能使用tab

2.  冒号: 后面如果接着有值那么冒号和值之间需要有空格

3.  每一项的相同级别的内容需要左对齐

 

 

------------------------------------


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM