linux常识:管理IP地址

方法一:使用命令ifconfig

ifconfig 网络设备 IP地址 hw MAC地址 netmask 掩码地址 broadcast 广播地址 [up/down]

//网卡关闭与激活
# ifconfig eth0 down
# ifconfig eth0 up
# ifdown eth0
# ifup eth1

//查看网卡信息
# ifconfig [-a]
# ifconfig eth0

//设置IP信息
# ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx
# ifconfig eth0 192.168.10.110 netmask 255.255.255.0 mtu 1412 up
# ifconfig eth1 192.168.10.221 netmask 255.255.255.0 broadcast 192.168.10.255 up
# ifconfig eth1 192.168.10.221 hw ether xx:xx:xx:xx:xx:xx netmask 255.255.255.0 broadcast 192.168.10.255 mtu 1412 up

//添加虚拟网卡
# ifconfig eth0 192.168.10.110 hw ether xx:xx:xx:xx:xx:xx netmask 255.255.255.0 up

方法二:使用命令ip address

//查看ip状态
# ip address show
# ip address show dev eth0

//添加ip地址
# ip address add 192.168.10.110/24 brd + dev eth0
# ip address add 192.168.10.221/24 brd + dev eth0 label eth0:0

//删除ip地址
# ip address del 192.168.10.110/24 brd + dev eth0

//清空ip设置
# ip address flush dev eth0
# ip address show dev eth0

//此状态下ifconfig无法查看到第二IP
# ip address add 192.168.10.110/24 brd + dev eth0
# ip address add 192.168.10.221/24 brd + dev eth0
# ip address show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 100
link/ether 00:80:c8:f8:4a:51 brd ff:ff:ff:ff:ff:ff
inet 192.168.10.110/24 brd 192.168.10.255 scope global eth0
inet 192.168.10.221/24 brd 192.168.10.255 scope global secondary eth0

//此状态下ifconfig可以查看到第二IP
# ip address add 192.168.10.110/24 brd + dev eth0
# ip address add 192.168.10.221/24 brd + dev eth0:0
# ip address show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 100
link/ether 00:80:c8:f8:4a:51 brd ff:ff:ff:ff:ff:ff
inet 192.168.10.110/24 brd 192.168.10.255 scope global eth0
inet 192.168.10.221/24 brd 192.168.10.255 scope global secondary eth0:0

注意问题:
ifconfig和ip address添加的IP重启后都会失效,可通过修改/etc/sysconfig/network-scripts/ifcfg-eth0,/etc/sysconfig/network-scripts/ifcfg-eth0:0设置固定IP。

参考链接:
http://linux-ip.net/html/tools-ifconfig.html
http://linux-ip.net/html/tools-ip-address.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值