一、centOS

1、编辑 ifcfg-eth0 文件

# vim /etc/sysconfig/network-scripts/ifcfg-eth0  

2,在文件中新增下列配置,HWADDR需要换成自己机器上的

BOOTPROTO="static" #dhcp改为static   
ONBOOT="yes" #开机启用本配置  
IPADDR=192.168.1.106 #静态IP  
GATEWAY=192.168.7.1 #默认网关  
NETMASK=255.255.255.0 #子网掩码  
DNS1=192.168.7.1 #DNS 配置 

效果图:

CentOS、乌班图设置固定静态IP

3.重启网络服务

service network restart 

  

 二、乌班图

1、编辑interfaces文件

vim /etc/network/interfaces

2、新增下列内容:

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

效果图:

CentOS、乌班图设置固定静态IP

3、设置DNS:

vim /etc/resolv.conf

 新增下列内容:

nameserver 192.168.1.1
nameserver 8.8.8.8

4、上一步的设置重启后就会发生变化,所以需要设置成固定的:

vim /etc/resolvconf/resolv.conf.d/base

新增内容:

nameserver 192.168.1.1
nameserver 8.8.8.8

5、重启网络服务:

/etc/init.d/networking restart

上面命令无效时,使用这条命令:

sudo ifdown eth0 && sudo ifup eth0

  

 

 

 

  

 

相关文章:

  • 2022-01-07
  • 2021-10-07
  • 2021-05-05
  • 2021-06-13
  • 2021-08-14
  • 2021-11-04
  • 2021-10-16
猜你喜欢
  • 2021-11-21
  • 2021-11-01
  • 2022-12-23
  • 2022-01-15
  • 2021-09-24
  • 2021-11-20
  • 2021-09-12
相关资源
相似解决方案