如何在 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