2013年3月1日
為ip添加别名
一、檢視狀态
[root@desktop7 ~]# ifconfig
br0 link encap:ethernet hwaddr 50:46:5d:71:c2:f1
inet addr:192.168.0.7 bcast:192.168.0.255 mask:255.255.255.0
inet6 addr: fe80::5246:5dff:fe71:c2f1/64 scope:link
up broadcast running multicast mtu:1500 metric:1
rx packets:27002 errors:0 dropped:0 overruns:0 frame:0
tx packets:6410 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
rx bytes:33859254 (32.2 mib) tx bytes:513684 (501.6 kib)
eth0 link encap:ethernet hwaddr 50:46:5d:71:c2:f1
rx packets:1564063 errors:0 dropped:0 overruns:0 frame:0
tx packets:392416 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
rx bytes:2157659980 (2.0 gib) tx bytes:26901971 (25.6 mib)
interrupt:233 base address:0x6000
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:33670 errors:0 dropped:0 overruns:0 frame:0
tx packets:33670 errors:0 dropped:0 overruns:0 carrier:0
rx bytes:130529766 (124.4 mib) tx bytes:130529766 (124.4 mib)
virbr0 link encap:ethernet hwaddr fe:52:00:48:13:31
inet addr:192.168.122.1 bcast:192.168.122.255 mask:255.255.255.0
rx packets:692 errors:0 dropped:0 overruns:0 frame:0
tx packets:75 errors:0 dropped:0 overruns:0 carrier:0
rx bytes:76119 (74.3 kib) tx bytes:11775 (11.4 kib)
vnet0 link encap:ethernet hwaddr fe:52:00:48:13:31
inet6 addr: fe80::fc52:ff:fe48:1331/64 scope:link
tx packets:13836 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
rx bytes:85819 (83.8 kib) tx bytes:728262 (711.1 kib)
vnet1 link encap:ethernet hwaddr fe:54:00:00:00:6b
inet6 addr: fe80::fc54:ff:fe00:6b/64 scope:link
rx packets:258 errors:0 dropped:0 overruns:0 frame:0
tx packets:3093 errors:0 dropped:0 overruns:0 carrier:0
rx bytes:26456 (25.8 kib) tx bytes:483828 (472.4 kib)
vnet2 link encap:ethernet hwaddr fe:54:00:00:00:cf
inet6 addr: fe80::fc54:ff:fe00:cf/64 scope:link
rx packets:241 errors:0 dropped:0 overruns:0 frame:0
tx packets:3017 errors:0 dropped:0 overruns:0 carrier:0
rx bytes:24669 (24.0 kib) tx bytes:472463 (461.3 kib)
二、添加别名
1、用ifconfig添加 ip 别名
[root@desktop7 ~]# ifconfig eth0:1 192.168.2.1 broadcast 192.168.0.7 netmask 255.255.255.0 up
2、設定路由
[root@desktop7 ~]# route add -host 192.168.2.1 dev eth0:1
3、檢視設定狀況
rx packets:29549 errors:0 dropped:0 overruns:0 frame:0
tx packets:7008 errors:0 dropped:0 overruns:0 carrier:0
rx bytes:36108533 (34.4 mib) tx bytes:557643 (544.5 kib)
rx packets:1566606 errors:0 dropped:0 overruns:0 frame:0
tx packets:393031 errors:0 dropped:0 overruns:0 carrier:0
rx bytes:2159945517 (2.0 gib) tx bytes:26949905 (25.7 mib)
eth0:1 link encap:ethernet hwaddr 50:46:5d:71:c2:f1
inet addr:192.168.2.1 bcast:192.168.0.7 mask:255.255.255.0
rx packets:747 errors:0 dropped:0 overruns:0 frame:0
tx packets:81 errors:0 dropped:0 overruns:0 carrier:0
rx bytes:82101 (80.1 kib) tx bytes:12821 (12.5 kib)
tx packets:14828 errors:0 dropped:0 overruns:0 carrier:0
rx bytes:92571 (90.4 kib) tx bytes:780580 (762.2 kib)
rx packets:260 errors:0 dropped:0 overruns:0 frame:0
tx packets:4252 errors:0 dropped:0 overruns:0 carrier:0
rx bytes:26684 (26.0 kib) tx bytes:855793 (835.7 kib)
rx packets:243 errors:0 dropped:0 overruns:0 frame:0
tx packets:4176 errors:0 dropped:0 overruns:0 carrier:0
rx bytes:24897 (24.3 kib) tx bytes:844428 (824.6 kib)
三、驗證
1、ssh本機虛拟機
[root@desktop7 ~]# ssh 192.168.0.230
the authenticity of host '192.168.0.230 (192.168.0.230)' can't be established.
rsa key fingerprint is fc:3b:67:f0:66:44:a5:2f:84:c4:e0:b6:74:4d:ff:93.
are you sure you want to continue connecting (yes/no)? yes
warning: permanently added '192.168.0.230' (rsa) to the list of known hosts.
[email protected]'s password:
last login: fri mar 1 03:15:21 2013
2、檢視虛拟機ip
[root@localhost ~]# ifconfig
eth0 link encap:ethernet hwaddr 52:54:00:00:00:6b
inet addr:192.168.0.230 bcast:192.168.0.255 mask:255.255.255.0
inet6 addr: fe80::5054:ff:fe00:6b/64 scope:link
rx packets:5429 errors:0 dropped:0 overruns:0 frame:0
tx packets:450 errors:0 dropped:0 overruns:0 carrier:0
rx bytes:1146759 (1.0 mib) tx bytes:47530 (46.4 kib)
rx packets:1580 errors:0 dropped:0 overruns:0 frame:0
tx packets:1580 errors:0 dropped:0 overruns:0 carrier:0
rx bytes:4868050 (4.6 mib) tx bytes:4868050 (4.6 mib)
3、ping新ip 192.168.2.1
[root@localhost ~]# ping 192.168.2.1
ping 192.168.2.1 (192.168.2.1) 56(84) bytes of data.
64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=1.63 ms
from 192.168.0.254: icmp_seq=2 redirect host(new nexthop: 192.168.2.1)
64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=0.328 ms
from 192.168.0.254: icmp_seq=3 redirect host(new nexthop: 192.168.2.1)
64 bytes from 192.168.2.1: icmp_seq=3 ttl=64 time=0.314 ms
64 bytes from 192.168.2.1: icmp_seq=4 ttl=64 time=0.247 ms
64 bytes from 192.168.2.1: icmp_seq=5 ttl=64 time=0.256 ms
64 bytes from 192.168.2.1: icmp_seq=6 ttl=64 time=0.217 ms
64 bytes from 192.168.2.1: icmp_seq=7 ttl=64 time=0.602 ms
64 bytes from 192.168.2.1: icmp_seq=8 ttl=64 time=0.216 ms
64 bytes from 192.168.2.1: icmp_seq=9 ttl=64 time=0.206 ms
64 bytes from 192.168.2.1: icmp_seq=10 ttl=64 time=0.185 ms
--- 192.168.2.1 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9002ms
rtt min/avg/max/mdev = 0.185/0.420/1.631/0.419 ms
再ping 192.168.2.1
64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=0.176 ms
64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=0.250 ms
64 bytes from 192.168.2.1: icmp_seq=3 ttl=64 time=0.211 ms
64 bytes from 192.168.2.1: icmp_seq=4 ttl=64 time=0.213 ms
64 bytes from 192.168.2.1: icmp_seq=5 ttl=64 time=0.238 ms
64 bytes from 192.168.2.1: icmp_seq=6 ttl=64 time=0.173 ms
6 packets transmitted, 6 received, 0% packet loss, time 5000ms
rtt min/avg/max/mdev = 0.173/0.210/0.250/0.029 ms
[root@localhost ~]#
四、永久生效,配置檔案
[root@localhost ~]# vi /etc/rc.local
#!/bin/sh
#
# this script will be executed *after* all the other init scripts.
# you can put your own initialization stuff in here if you don't
# want to do the full sys v style init stuff.
touch /var/lock/subsys/local
(增加以下兩行内容)
ifconfig eth0:1 192.168.2.1 broadcast 192.168.0.7 netmask 255.255.255.0 up
route add -host 192.168.2.1 dev eth0:1