在Linux系统中,修改IP地址后要使其马上生效,可以通过以下几种方法:
一、使用命令行临时修改(重启后失效)
ifconfig
命令的系统(较旧的系统,如CentOS 6等)eth0
网卡的IP地址为192.168.1.100
,子网掩码为255.255.255.0
。ifconfig eth0 192.168.1.100 netmask 255.255.255.0
192.168.1.1
),可以使用route
命令:route add default gw 192.168.1.1 eth0
ip
命令的系统(较新的系统,如CentOS 7+、Ubuntu等)ens33
网卡的IP地址修改为192.168.1.100
,子网掩码为24
位(等同于255.255.255.0
)。ip addr add 192.168.1.100/24 dev ens33
。192.168.1.1
):ip route add default via 192.168.1.1
二、永久修改IP地址(重启后仍然有效)
nmcli connection show
。Wired\ connection\ 1
,修改IP地址为192.168.1.100
,子网掩码24
位,可以使用以下命令:nmcli connection modify "Wired\ connection\ 1" ipv4.addresses 192.168.1.100/24
nmcli connection modify "Wired\ connection\ 1" ipv4.gateway 192.168.1.1
nmcli connection modify "Wired\ connection\ 1" ipv4.method manual
nmcli connection up "Wired\ connection\ 1"
/etc/sysconfig/network - scripts/
目录下,文件名为ifcfg - eth0
(如果有多个网卡,如ifcfg - ens33
等)。IPADDR = 192.168.1.100
NETMASK = 255.255.255.0
GATEWAY = 192.168.1.1
。systemctl restart network
(在CentOS 7+中)或者service network restart
(在CentOS 6等系统中)。领取专属 10元无门槛券
手把手带您无忧上云