ubuntu配置网络信息

环境:
Os:18.04.1/16.04

 

##############################################18.04#######################################

1.备份配置文件
root@11g:~# cd /etc/netplan
root@11g:/etc/netplan#
root@11g:/etc/netplan# cp 01-network-manager-all.yaml bak_01-network-manager-all.yaml

 

2.配置静态ip

# Let NetworkManager manage all devices on this system
network:
  ethernets:
    enp0s3:
      addresses: [192.168.56.101/24]
      gateway4: 192.168.56.1
      dhcp4: no
      dhcp6: no
      nameservers:
              addresses: [8.8.8.8,8.8.4.4]
      optional: true
  version: 2

 

3.配置完成后,应用命令:

root@11g:/etc/netplan# netplan apply
/etc/netplan/01-network-manager-all.yaml:12:4: Invalid YAML: inconsistent indentation:
   version: 2      
   ^

 

我这里上格式问题,调整后再次执行,最后文件内如如下:

root@11g:/etc/netplan# more 01-network-manager-all.yaml 
# Let NetworkManager manage all devices on this system
network:
  ethernets:
    enp0s3:
      addresses: [192.168.56.101/24]
      gateway4: 192.168.56.1
      dhcp4: no
      dhcp6: no
      nameservers:
        addresses: [8.8.8.8,8.8.4.4]
      optional: true
  version: 2

 

说明:

若/etc/netplan下有其他备份文件的话,发现netpan apply不起作用,删除备份文件后重新执行netpan apply后才启作用.

 

#######################################16.04###########################################################

root@11g:/etc/network# cd /etc/network/

编辑文件interfaces进行修改,建议备份下原有文件

root@11g:/etc/network# more interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto enp0s3
iface enp0s3 inet static
        address 192.168.56.101
        netmask 255.255.255.0
        network 192.168.0.0
        broadcast 192.168.56.255
        gateway 192.168.56.1

 

然后重启网络

/etc/init.d/networking restart

 

posted @ 2024-07-01 16:11  slnngk  阅读(37)  评论(0编辑  收藏  举报