永久配置静态IP地址
linux-t1qq:~ # cd /etc/sysconfig/network/
linux-t1qq:/etc/sysconfig/network # vi ifcfg-eth0
BOOTPROT='DHCP'
改为BOOTPROT='static'
修改IPADDR和NETMASK
若修改另一个网卡,但没有相关配置文件,可将其他网卡的配置文件复制过来进行修改。
linux-t1qq:/etc/sysconfig/network # cp ifcfg-eth0 /etc/sysconfig/network/ifcfg-eth1
linux-t1qq:/etc/sysconfig/network # servcie network restart # 重启网络服务
临时配置静态ip
# ifconfig eth2 192.168.1.217 netmask 255.255.255.0 up # 重启网络服务后失效
问题:eth0修改静态IP后,无法上网
linux-t1qq:/etc/sysconfig/network # vi routes # 添加默认网关,若无routes文件则创建
使用route
或route -n
查看route表,看默认路由是否缺少或配置错误。
# route add default gw 172.27.0.1 dev eth0 # 添加默认路由走eth0
其他ifconfig命令
# ifconfig eth0 up # 启用网卡设备
# ifconfig eth0 down # 禁用网卡设备