Centos7修改ip地址
查看ip地址
ifconfig # 方式1
## 这个名字的文件是我们需要修改的
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.172 netmask 255.255.255.0 broadcast 192.168.100.255
inet6 fe80::4b9b:8d53:fba3:3964 prefixlen 64 scopeid 0x20<link>
ether 00:50:56:86:41:b4 txqueuelen 1000 (Ethernet)
RX packets 5829 bytes 752184 (734.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 434 bytes 59083 (57.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 72458 bytes 23024000 (21.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 72458 bytes 23024000 (21.9 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:11:12:2b txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ip addr # 方式2
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:50:56:86:41:b4 brd ff:ff:ff:ff:ff:ff
inet 192.168.100.42/24 brd 192.168.100.255 scope global noprefixroute ens32
valid_lft forever preferred_lft forever
inet6 fe80::4b9b:8d53:fba3:3964/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:11:12:2b brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:11:12:2b brd ff:ff:ff:ff:ff:ff
修改配置文件:
vim /etc/sysconfig/network-scripts/ifcfg-ens32 # 文件名来源于上面
## 文件中修改或者添加以下内容
BOOTPROTO="static" #dhcp改为static
ONBOOT="yes" #开机启用本配置
IPADDR=192.168.7.106 #静态IP
GATEWAY=192.168.7.1 #默认网关
NETMASK=255.255.255.0 #子网掩码
DNS1=192.168.7.1 #DNS 配置
重启网络服务:
service network restart
看看能不能上网:
ping baidu.com # 如果成功则ok了。不成功就得检查一下配置
Centos7修改ip地址
https://qiil.github.io/2022/08/15/Centos7修改ip地址/