1、IP地址概述
2、配置IP地址
查看IP地址
在网卡上绑定一个IP地址
同一张网卡上绑定多个IP
绑定一块网卡设备
修改或删除IP地址
IP地址概述
这里不多赘述,参考《计算机网络》课程。
配置IP地址
[root@weekend110 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:05:1D:AC 网卡的物理地址
inet addr:192.168.80.110 Bcast:192.168.80.255 Mask:255.255.255.0 IP地址、广播地址、子网掩码
inet6 addr: fe80::20c:29ff:fe05:1dac/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 UP表示该网络接口是启动的
RX packets:33148 errors:0 dropped:0 overruns:0 frame:0 该网络接口上的数据包统计信息
TX packets:12115 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:41678800 (39.7 MiB) TX bytes:2688713 (2.5 MiB)
lo Link encap:Local Loopback 内部网络回环地址
inet addr:127.0.0.1 Mask:255.0.0.0 回环IP地址、子网掩码
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:720 (720.0 b) TX bytes:720 (720.0 b)
[root@weekend110 ~]#
ifconfig -a 显示包括激活和未激活的全部网络接口
ifconfig -s 只显示网络接口的摘要信息
[root@weekend110 ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:05:1D:AC
inet addr:192.168.80.110 Bcast:192.168.80.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe05:1dac/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:33308 errors:0 dropped:0 overruns:0 frame:0
TX packets:12143 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:41693344 (39.7 MiB) TX bytes:2692561 (2.5 MiB)
[root@weekend110 ~]#
[root@weekend110 ~]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:0C:29:05:1D:AC
inet addr:192.168.80.110 Bcast:192.168.80.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe05:1dac/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:33336 errors:0 dropped:0 overruns:0 frame:0
TX packets:12160 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:41695906 (39.7 MiB) TX bytes:2694923 (2.5 MiB)
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:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:720 (720.0 b) TX bytes:720 (720.0 b)
[root@weekend110 ~]#
在网卡上绑定一个IP地址
[root@weekend110 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 网卡设备名称
HWADDR=00:0C:29:05:1D:AC
TYPE=Ethernet
UUID=a36d5f1e-fa69-453f-ba2b-a0952b279936
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
IPADDR=192.168.80.110 绑定的IP地址
BCAST=192.168.80.255
GATEWAY=192.168.80.2
NETMASK=255.255.255.0
DNS1=144.144.144.144
DNS2=192.168.80.2
[root@weekend110 ~]#
[root@weekend110 network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@weekend110 network-scripts]# ifdown eth0 关闭网卡eth0
[root@weekend110 network-scripts]# ifup eth0 打开网卡eth0
或者
[root@weekend110 network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@weekend110 network-scripts]# ./ifdown eth0 关闭网卡eth0
[root@weekend110 network-scripts]# ./ifup eth0 打开网卡eth0
或者
[root@weekend110 ~]# /etc/sysconfig/network-scripts/ifdown eth0 关闭网卡eth0
[root@weekend110 ~]# /etc/sysconfig/network-scripts/ifup eth0 打开网卡eth0
同一张网卡上绑定多个IP
在实际工作中,特别是在服务器上,需要在一张网卡上配置大量的IP地址。我们可以通过利用虚拟网卡技术来实现这个需求。
利用虚拟网卡技术,为此张网卡设置一些别名的配置文件,并利用这些别名的配置文件在这张网卡上绑定多个IP地址。
如果,需要在一块网卡上绑定多个IP地址,就需要手动设置多个以ifcfg-开头并且后接该网卡名字(逻辑名)的配置文件,其格式如下
ifcfg-ethX:YYY
其中,X是第几张网卡设备,YYY是该网卡设备上的第几张网卡。
如,网卡文件ifcfg-eth0:1中,eth0表示第一张网卡,而其后冒号后的数字,则表示eth0上的的第二张网卡。即ifcfg-eth0:1则表示第一张网卡上的第二块网卡。
参考:http://blog.sina.com.cn/s/blog_5f54f0be0101josm.html
http://jingyan.baidu.com/article/ea24bc3986dab0da62b331ab.html
[root@weekend110 network-scripts]# ls
ifcfg-eth0 ifdown-eth ifdown-post ifdown-tunnel ifup-eth ifup-plip ifup-routes init.ipv6-global
ifcfg-lo ifdown-ippp ifdown-ppp ifup ifup-ippp ifup-plusb ifup-sit net.hotplug
ifdown ifdown-ipv6 ifdown-routes ifup-aliases ifup-ipv6 ifup-post ifup-tunnel network-functions
ifdown-bnep ifdown-isdn ifdown-sit ifup-bnep ifup-isdn ifup-ppp ifup-wireless network-functions-ipv6
[root@weekend110 network-scripts]#
默认,只看到ifcfg-eth0 文件。这里,复制一份,命名为ifcfg-eth0:0
[root@weekend110 network-scripts]# ls
ifcfg-eth0 ifdown-eth ifdown-post ifdown-tunnel ifup-eth ifup-plip ifup-routes init.ipv6-global
ifcfg-lo ifdown-ippp ifdown-ppp ifup ifup-ippp ifup-plusb ifup-sit net.hotplug
ifdown ifdown-ipv6 ifdown-routes ifup-aliases ifup-ipv6 ifup-post ifup-tunnel network-functions
ifdown-bnep ifdown-isdn ifdown-sit ifup-bnep ifup-isdn ifup-ppp ifup-wireless network-functions-ipv6
[root@weekend110 network-scripts]# cp ifcfg-eth0 ifcfg-eth0:1
[root@weekend110 network-scripts]# ls
ifcfg-eth0 ifdown-eth ifdown-ppp ifup-aliases ifup-isdn ifup-routes net.hotplug
ifcfg-eth0:1 i fdown-ippp ifdown-routes ifup-bnep ifup-plip ifup-sit network-functions
ifcfg-lo ifdown-ipv6 ifdown-sit ifup-eth ifup-plusb ifup-tunnel network-functions-ipv6
ifdown ifdown-isdn ifdown-tunnel ifup-ippp ifup-post ifup-wireless
ifdown-bnep ifdown-post ifup ifup-ipv6 ifup-ppp init.ipv6-global
[root@weekend110 network-scripts]# vim ifcfg-eth0:1
DEVICE=eth0:1
HWADDR=00:0C:29:05:1D:AC
TYPE=Ethernet
UUID=a36d5f1e-fa69-453f-ba2b-a0952b279936
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0:1"
IPADDR=192.168.80.111
BCAST=192.168.80.255
GATEWAY=192.168.80.2
NETMASK=255.255.255.0
DNS1=144.144.144.144
DNS2=192.168.80.2
[root@weekend110 network-scripts]# service network restart
Shutting down interface eth0: Device state: 3 (disconnected)
[ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Active connection state: activating
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/2
state: activated
Connection activated
[ OK ]
[root@weekend110 network-scripts]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:05:1d:ac brd ff:ff:ff:ff:ff:ff
inet 192.168.80.110/24 brd 192.168.80.255 scope global eth0
inet 192.168.80.111/24 brd 192.168.80.255 scope global secondary eth0:1
inet6 fe80::20c:29ff:fe05:1dac/64 scope link
valid_lft forever preferred_lft forever
[root@weekend110 network-scripts]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:05:1D:AC
inet addr:192.168.80.110 Bcast:192.168.80.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe05:1dac/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:572 errors:0 dropped:0 overruns:0 frame:0
TX packets:355 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:53584 (52.3 KiB) TX bytes:42335 (41.3 KiB)
eth0:1 Link encap:Ethernet HWaddr 00:0C:29:05:1D:AC
inet addr:192.168.80.111 Bcast:192.168.80.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
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:4 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:240 (240.0 b) TX bytes:240 (240.0 b)
[root@weekend110 network-scripts]#
测试,网络
Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
C:\Users\Administrator>ping 192.168.80.110
正在 Ping 192.168.80.110 具有 32 字节的数据:
来自 192.168.80.110 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.80.110 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.80.110 的回复: 字节=32 时间<1ms TTL=64
192.168.80.110 的 Ping 统计信息:
数据包: 已发送 = 3,已接收 = 3,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms
Control-C
^C
C:\Users\Administrator>ping 192.168.80.111
正在 Ping 192.168.80.111 具有 32 字节的数据:
来自 192.168.80.111 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.80.111 的回复: 字节=32 时间<1ms TTL=64
192.168.80.111 的 Ping 统计信息:
数据包: 已发送 = 2,已接收 = 2,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms
Control-C
^C
C:\Users\Administrator>
删除
[root@weekend110 network-scripts]# ls
ifcfg-eth0 ifdown-eth ifdown-ppp ifup-aliases ifup-isdn ifup-routes net.hotplug
ifcfg-eth0:1 ifdown-ippp ifdown-routes ifup-bnep ifup-plip ifup-sit network-functions
ifcfg-lo ifdown-ipv6 ifdown-sit ifup-eth ifup-plusb ifup-tunnel network-functions-ipv6
ifdown ifdown-isdn ifdown-tunnel ifup-ippp ifup-post ifup-wireless
ifdown-bnep ifdown-post ifup ifup-ipv6 ifup-ppp init.ipv6-global
[root@weekend110 network-scripts]# rm -rf ifcfg-eth0:1
其他的,不多赘述。
图形界面呢,如何来做到?
这里不多,赘述。
修改或删除IP地址
这里不多,赘述。