在 Linux 中,ifconfig 可以用来临时配置 IP 地址(重启网络或系统后失效)。下面是常见用法。
ifconfig
或
ifconfig -a
ifconfig eth0 192.168.1.100 netmask 255.255.255.0
说明:
eth0:网卡名(可能是 ens33、enp0s3 等)192.168.1.100:IP 地址netmask:子网掩码route add default gw 192.168.1.1
或
ip route add default via 192.168.1.1
ifconfig eth0 up
ifconfig eth0 down
ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
ifconfig eth0:0 192.168.1.101 netmask 255.255.255.0
ifconfig 已逐步被弃用/etc/sysconfig/network-scripts//etc/network/interfacesnetplanip addr、ip routeip addr add 192.168.1.100/24 dev eth0
ip link set eth0 up
如果你告诉我 Linux 发行版(CentOS / Ubuntu 等) 和 是否要永久生效,我可以给你具体配置方法。