本來的網卡是 eth0 ,IP 是 192.168.75.55/24
[root@ithelp ~]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:0c:29:0f:d7:c6 brd ff:ff:ff:ff:ff:ff
inet 192.168.75.55/24 brd 192.168.75.255 scope global eth0
inet6 fe80::20c:29ff:fe0f:d7c6/64 scope link
valid_lft forever preferred_lft forever
透過指令新增第二個IP在eth0 (secondary IP)
[root@ithelp ~]# ip addr add 192.168.75.110/24 dev eth0
[root@ithelp. ~]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:0c:29:0f:d7:c6 brd ff:ff:ff:ff:ff:ff
inet 192.168.75.55/24 brd 192.168.75.255 scope global eth0
<strong>inet 192.168.75.110/24 scope global secondary eth0</strong>
inet6 fe80::20c:29ff:fe0f:d7c6/64 scope link
valid_lft forever preferred_lft forever
但這個要如何寫到設定檔中,讓開機就可以生效。
已知方法(但想找別的,若有的話..):
寫到 /etc/rc.local,但不知是否透過寫 ifcfg-eth* 就可以達成
新增 ifcfg-eth0:X 的 alias 介面.
(但這個新增出來的,會有:X感覺怪怪的..像下面的)
[root@ithelp ~]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:0c:29:0f:d7:c6 brd ff:ff:ff:ff:ff:ff
inet 192.168.75.55/24 brd 192.168.75.255 scope global eth0
<strong>inet 192.168.75.110/24 brd 192.168.75.255 scope global secondary eth0:1</strong>
inet6 fe80::20c:29ff:fe0f:d7c6/64 scope link
valid_lft forever preferred_lft forever
因此想知道,是否各位有其它的方法? 感謝
這一篇文說明得蠻清楚:
Linux Creating or Adding New Network Alias To a Network Card (NIC)
<pre class="c" name="code"># cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0
# vi /etc/sysconfig/network-scripts/ifcfg-eth0:0
#內容類似以下:
DEVICE=eth0:0
IPADDR=192.168.1.7
NETMASK=255.255.255.0
NETWORK=192.168.1.0
ONBOOT=yes
NAME=eth0:0
修改 ifcfg-eth0 為在 GETWAY的設定加上 #
<pre class="c" name="code"># vi /etc/sysconfig/network-scripts/ifcfg-eth0
#把下面一行前面加上 #
# GATEWAY=192.168.1.254
把gate way 的設定改在
<pre class="c" name="code"># vi /etc/sysconfig/network
#新增這一行:
GATEWAY=192.168.1.254