查看自己的ip信息:
[root@slave5 conf]# ifconfig eth0 Link encap:Ethernet HWaddr E0:CB:4E:D0:EC:B2 inet addr:192.168.30.149 Bcast:192.168.30.255 Mask:255.255.255.0 inet6 addr: fe80::e2cb:4eff:fed0:ecb2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:48458926 errors:0 dropped:0 overruns:0 frame:0 TX packets:40842760 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1562626110 (1.4 GiB) TX bytes:330009772 (314.7 MiB) Interrupt:233 Base address:0xe000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:25711326 errors:0 dropped:0 overruns:0 frame:0 TX packets:25711326 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2575592225 (2.3 GiB) TX bytes:2575592225 (2.3 GiB)
eth0和本地回环设备lo,127.0.0.1,通常被称为本地回环地址(Loop back address),不属于任何一个有类别地址类。它代表设备的本地虚拟接口,所以默认被看作是永远不会宕掉的接口。在windows操作系统中也有相似的定义,所以通常在不安装网卡前就可以ping通这个本地回环地址。一般都会用来检查本地网络协议、基本数据接口等是否正常的。
在基础上增加一个ip别名
[root@slave5 conf]# ifconfig eth0:1 192.168.30.121 broadcast 192.168.30.255 netmask 255.255.255.0 up [root@slave5 conf]# route add -host 192.168.30.121 dev eth0:1
查看ifconfig
[root@slave5 conf]# ifconfig eth0 Link encap:Ethernet HWaddr E0:CB:4E:D0:EC:B2 inet addr:192.168.30.149 Bcast:192.168.30.255 Mask:255.255.255.0 inet6 addr: fe80::e2cb:4eff:fed0:ecb2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:48460536 errors:0 dropped:0 overruns:0 frame:0 TX packets:40843834 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1562794737 (1.4 GiB) TX bytes:330131620 (314.8 MiB) Interrupt:233 Base address:0xe000 eth0:1 Link encap:Ethernet HWaddr E0:CB:4E:D0:EC:B2 inet addr:192.168.30.121 Bcast:192.168.30.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:233 Base address:0xe000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:25711330 errors:0 dropped:0 overruns:0 frame:0 TX packets:25711330 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2575592673 (2.3 GiB) TX bytes:2575592673 (2.3 GiB)
用另外一台主机,如果能平通说明成功。
[root@slave5 ~]# ping 192.168.30.123 PING 192.168.30.123 (192.168.30.123) 56(84) bytes of data. 64 bytes from 192.168.30.123: icmp_seq=1 ttl=64 time=0.018 ms 64 bytes from 192.168.30.123: icmp_seq=2 ttl=64 time=0.011 ms 64 bytes from 192.168.30.123: icmp_seq=3 ttl=64 time=0.009 ms 64 bytes from 192.168.30.123: icmp_seq=4 ttl=64 time=0.008 ms
要注意的是,上述配置信息重启后会消失,如何配置不消失信息。如下
将ifconfig和rout命令添加到/etc/rc.local文件中
vi /etc/rc.local
在文件末尾叫上如下内容:
[root@slave5 conf]# ifconfig eth0:1 192.168.30.121 broadcast 192.168.30.255 netmask 255.255.255.0 up [root@slave5 conf]# route add -host 192.168.30.121 dev eth0:1