linux之cenos7修改ip(临时和永久)

1,临时修改ip

ifconfig 网卡名称 ip地址 – 直接修改网卡ip,重启失效

//设置ip
 [root@localhost ~]# ifconfig ens33 192.168.43.137
//重启网络
 [root@localhost ~]# systemctl restart network

在这里插入图片描述
在这里插入图片描述

2,添加多个临时ip

ifconfig 网卡名称:0 第一个IP地址 ( netmask子网掩码)-增加一个IP,子网掩码默认255.255.255.0
config 网卡名称:1 第二个IP地址 ( netmask子网掩码)-增加一个IP

//给网卡添加多个ip
[root@localhost ~]# ifconfig ens33:0 192.168.43.11 up
[root@localhost ~]# ifconfig ens33:1 192.168.43.12 up
//重启后失效
 [root@localhost ~]# systemctl restart network

添加多个临时ip
在这里插入图片描述
删除临时ip
在这里插入图片描述

3,永久修改ip(使用nmtui文本框修改ip

[root@localhost ~]# nmtui

一直返回然后保存退出,重启后生效

3,永久修改ip( 修改配置文件修改ip)

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
//打开后注意的地方
BOOTPROTO=none         #等号后面写:dhcp表示动态获取ip地址,statis表示静态ip,none表示不指定,就是静态
ONBOOT=yes			# 在系统引导是是否激活此设备

vim快捷键:

i:进入插入模式
保存:先按eSc键,再输入:Wq
在这里插入图片描述

有个需要注意的地方,当配置完ip后,如果无法访问外网,呢么修改如下
[root@localhost network-scripts]# vi /etc/resolv.conf 

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44797182/article/details/110917379