Linux基础入门之网络属性配置之单接口配置多IP+TUI界面配置IP

  • A+
所属分类:Linux  Linux基础  Linux网络
摘要

但网卡配置单IP的情况在实际应用中有时候是无法满足我们的需求的,譬如我们有多个业务跑在一台服务器上,我们不想多业务用同一个IP地址且出于成本考虑我们也不想额外再加硬件设备网卡了,那么这时候我们就需要配置单网卡多IP的配置了。本篇博文将介绍如何在RedHat系系统上配置但网卡多IP

单网卡配置多IP也是分两种的一种是静态配置一种是动态配置,还是像上篇博文所说的一样,静态配置是需要写到配置文件里面且是永久生效的,而动态配置是通过命令来实现的,这是及时生效但是不能永久有效的。

动态方式配置但网卡多IP

ifconfig IFNAME:# IPADDRES netmask MASK

例子:

[root@Legion100 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.100  Bcast:172.16.255.255  Mask:255.255.0.0
          inet6 addr: fe80::20c:29ff:fee6:2999/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:971 errors:0 dropped:0 overruns:0 frame:0
          TX packets:167 errors:0 dropped:0 overruns:0 carrier:0
          RX packets:971 errors:0 dropped:0 overruns:0 frame:0
          TX packets:167 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:138474 (135.2 KiB)  TX bytes:29363 (28.6 KiB)

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:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

[root@Legion100 ~]# ifconfig eth0:0 172.16.6.10 netmask 255.255.0.0
[root@Legion100 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.100  Bcast:172.16.255.255  Mask:255.255.0.0
          inet6 addr: fe80::20c:29ff:fee6:2999/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1033 errors:0 dropped:0 overruns:0 frame:0
          TX packets:193 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:144994 (141.5 KiB)  TX bytes:33939 (33.1 KiB)

eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.10  Bcast:172.16.255.255  Mask:255.255.0.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:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

[root@Legion100 ~]# 

Linux基础入门之网络属性配置之单接口配置多IP+TUI界面配置IP

 

Linux基础入门之网络属性配置之单接口配置多IP+TUI界面配置IP

静态方式配置但网卡多IP

[root@Legion100 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE="eth0:0"
BOOTPROTO="static"
IPV6INIT="no"
MTU="1500"
NM_CONTROLLED="no"
MTU="1500"
NM_CONTROLLED="no"
ONBOOT="yes"
TYPE="Ethernet"
IPADDR=172.16.6.120
NETMASK=255.255.0.0
GATEWAY=172.16.0.1
[root@Legion100 ~]# service network restart
正在关闭接口 eth0:                                        [确定]
关闭环回接口:                                             [确定]
弹出环回接口:                                             [确定]
弹出界面 eth0:
正在决定 eth0 的 IP 信息...完成。
Determining if ip address 172.16.6.120 is already in use for device eth0...
                                                           [确定]
[root@Legion100 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.100  Bcast:172.16.255.255  Mask:255.255.0.0
          inet6 addr: fe80::20c:29ff:fee6:2999/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2700 errors:0 dropped:0 overruns:0 frame:0
          TX packets:811 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:359885 (351.4 KiB)  TX bytes:157465 (153.7 KiB)

eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.120  Bcast:172.16.255.255  Mask:255.255.0.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:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

[root@Legion100 ~]# 

Linux基础入门之网络属性配置之单接口配置多IP+TUI界面配置IP

上面这种添加多IP的在某些环境下还是比较麻烦的譬如说我需要添加13个IP那么就要创建eth0:0 eth0:1......eth0:12这么多文件了,是不是也很烦躁?其实我们还可以用另外一种方式添加

[root@Legion100 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.100  Bcast:172.16.255.255  Mask:255.255.0.0
          inet6 addr: fe80::20c:29ff:fee6:2999/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5133 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1161 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:741882 (724.4 KiB)  TX bytes:232077 (226.6 KiB)

eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.120  Bcast:172.16.255.255  Mask:255.255.0.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:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

[root@Legion100 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0-range13
DEVICE=eth0
BOOTPROTO=static
CLONENUM_START=1
IPADDR_START=172.16.6.200
IPADDR_END=172.16.6.212
NETMASK=255.255.0.0
ONBOOT=yes
[root@Legion100 ~]# service network restart
正在关闭接口 eth0:                                        [确定]
关闭环回接口:                                             [确定]
弹出环回接口:                                             [确定]
弹出界面 eth0:
正在决定 eth0 的 IP 信息...完成。
Determining if ip address 172.16.6.120 is already in use for device eth0...
Determining if ip address 172.16.6.200 is already in use for device eth0...
Determining if ip address 172.16.6.201 is already in use for device eth0...
Determining if ip address 172.16.6.202 is already in use for device eth0...
Determining if ip address 172.16.6.203 is already in use for device eth0...
Determining if ip address 172.16.6.204 is already in use for device eth0...
Determining if ip address 172.16.6.205 is already in use for device eth0...
Determining if ip address 172.16.6.206 is already in use for device eth0...
Determining if ip address 172.16.6.207 is already in use for device eth0...
Determining if ip address 172.16.6.208 is already in use for device eth0...
Determining if ip address 172.16.6.209 is already in use for device eth0...
Determining if ip address 172.16.6.210 is already in use for device eth0...
Determining if ip address 172.16.6.211 is already in use for device eth0...
Determining if ip address 172.16.6.212 is already in use for device eth0...
                                                           [确定]
[root@Legion100 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.100  Bcast:172.16.255.255  Mask:255.255.0.0
          inet6 addr: fe80::20c:29ff:fee6:2999/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5305 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1277 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:762972 (745.0 KiB)  TX bytes:261915 (255.7 KiB)

eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.120  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.200  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:2    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.201  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:3    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.202  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:4    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.203  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:5    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.204  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:6    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.205  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:4    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.203  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:5    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.204  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:6    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.205  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:7    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99

eth0:5    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.204  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:6    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.205  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:7    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99

eth0:5    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.204  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:6    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.205  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:7    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.204  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:6    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.205  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:7    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99

eth0:7    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.206  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:8    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.207  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:9    Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.208  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:10   Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.209  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:11   Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.210  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:12   Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.211  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:13   Link encap:Ethernet  HWaddr 00:0C:29:E6:29:99
          inet addr:172.16.6.212  Bcast:172.16.255.255  Mask:255.255.0.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:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

[root@Legion100 ~]# 

Linux基础入门之网络属性配置之单接口配置多IP+TUI界面配置IP

使用TUI界面配置IP就简单多了,下面说说怎么用TUI界面来配置IP地址

直接运行命令system-config-network-tui命令就可以了

Linux基础入门之网络属性配置之单接口配置多IP+TUI界面配置IP

lookback

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: