Linux学习之路--添加IP别名

执行写道

ifconfig

 结果如下:写道

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:1746 errors:0 dropped:0 overruns:0 frame:0
                TX packets:1746 errors:0 dropped:0 overruns:0 carrier:0
                collisions:0 txqueuelen:0
                RX bytes:87540 (85.4 KiB) TX bytes:87540 (85.4 KiB)

p3p1      Link encap:Ethernet HWaddr 00:E0:6F:08:B6:85
                inet addr:192.168.1.121 Bcast:192.168.1.255 Mask:255.255.255.0
                inet6 addr: fe80::2e0:6fff:fe08:b685/64 Scope:Link
                UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
                RX packets:233870 errors:0 dropped:3 overruns:0 frame:0
                TX packets:182913 errors:0 dropped:0 overruns:0 carrier:0
                collisions:0 txqueuelen:1000
                RX bytes:324502272 (309.4 MiB) TX bytes:16169733 (15.4 MiB)
                Interrupt:23 Base address:0xcc00

lo为本地回环IP

p3p1是我的物理网卡

 

具体操作如下写道

/sbin/ifconfig p3p1:1 192.168.1.122 broadcast 192.168.1.255 netmask 255.255.255.0 up
/sbin/route add -host 192.168.1.122 def p3p2

/sbin/ifconfig p3p1:2 192.168.1.123 broadcast 192.168.1.255 netmask 255.255.255.0 up
/sbin/route add -host 192.168.1.123 def p3p3

 这样就会有多个IP,可以ping下测试

 

但重启之后就会消失,可以将这两条命令写到/etc/rc.local文件尾,让系统开机时自动运行即可。

你可能感兴趣的:(linux)