命令行修改linux系统IP
有时候服务器有多块网卡,查看哪块网卡插入网线并对其进行配置,使用ethtool eth0
root@b28-1346]# ethtool eth0 Settings for eth0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supports auto-negotiation: Yes Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Advertised auto-negotiation: Yes Speed: 1000Mb/s Duplex: Full Port: Twisted Pair PHYAD: 1 Transceiver: internal Auto-negotiation: on Supports Wake-on: g Wake-on: g Link detected: yes
修改配置文件/etc/sysconfig/network-scrips/ifcfg-eth0。因为机子启动的时候加载的就是这个文件的配置参数。对这个文件进行修改:
|
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 |
修改好后,要想将修改的配置不用重启而生效。输入命令
[root@localhost ~]# ifdown eth0
将eth0网络接口关闭,再输入下面的命令将eth0接口重新启动
[root@localhost ~]# ifup eth0
这个命令会到 /etc/sysconfig/network-scripts/下读取相应参数,使刚配置内容生效。
或者输入
[root@localhost ~]# /etc/init.d/network restart
或者输入
(1) sudo ifdown eth1 && sudo ifup eth1
如当前使用的网络设备是eth1,那么就连续执行上面两条命令即可,当然也可以分成两次执行(这种方法最直接)!
(2) sudo /etc/init.d/networking restart
这种方法最保险,因为它会重启配置文件里列出的所有网络设备,当然一般仅有一个是有效的(除了lo循环设备)!
即使是在dhcp模式下发生ip冲突而又不想使用静态ip,也是有办法可以解决的,就是再执行一遍dhclient3命令重新获得一次ip即可
浙公网安备 33010602011771号