Linux下一块网卡设置多个IP地址

Aorsking     发表于  2021-11-25 10:48       0
[root@rep1 ~]# ifconfig                             ###原来网卡的配置

eth0      Link encap:Ethernet  HWaddr 00:0C:29:D5:39:A0

inet addr:172.28.90.101  Bcast:172.28.255.255  Mask:255.255.0.0

inet6 addr: fe80::20c:29ff:fed5:39a0/64 Scope:Link

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:3125184 errors:0 dropped:0 overruns:0 frame:0

TX packets:101356 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:462342976 (440.9 MiB)  TX bytes:10788008 (10.2 MiB)

Interrupt:75 Base address:0x2000

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:1427 errors:0 dropped:0 overruns:0 frame:0

TX packets:1427 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:3335045 (3.1 MiB)  TX bytes:3335045 (3.1 MiB)

[root@rep1 ~]# cd /etc/sysconfig/net

netconsole       network          networking/      network-scripts/

[root@rep1 ~]# cd /etc/sysconfig/network-scripts/         #配置文件的目录路径

[root@rep1 network-scripts]# ls

ifcfg-eth0    ifdown-isdn    ifup-aliases  ifup-plip    ifup-wireless

ifcfg-lo      ifdown-post    ifup-bnep     ifup-plusb   init.ipv6-global

ifdown        ifdown-ppp     ifup-eth      ifup-post    net.hotplug

ifdown-bnep   ifdown-routes  ifup-ippp     ifup-ppp     network-functions

ifdown-eth    ifdown-sit     ifup-ipsec    ifup-routes  network-functions-ipv6

ifdown-ippp   ifdown-sl      ifup-ipv6     ifup-sit

ifdown-ipsec  ifdown-tunnel  ifup-ipx      ifup-sl

ifdown-ipv6   ifup           ifup-isdn     ifup-tunnel

[root@rep1 network-scripts]# cp ifcfg-eth0 ifcfg-eth0:1      #复制原来网卡配置

[root@rep1 network-scripts]# cp ifcfg-eth0 ifcfg-eth0:2     #复制原来网卡配置

[root@rep1 network-scripts]# vi ifcfg-eth0:1

# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]

DEVICE=eth0:1                                        #此处修改

BOOTPROTO=static

BROADCAST=172.28.255.255              #IP地址的广播地址

HWADDR=00:0C:29:D5:39:A0             #MAC地址,不用修改

IPADDR=172.28.90.201                         #设置新的IP

NETMASK=255.255.0.0

NETWORK=172.28.0.0

ONBOOT=yes

~

——————————————————————————————————

~

"ifcfg-eth0:1" 9L, 206C written

[root@rep1 network-scripts]# vi ifcfg-eth0:2

# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]

DEVICE=eth0:2                                                #此处修改

BOOTPROTO=static

BROADCAST=172.28.255.255                    #IP地址的广播地址

HWADDR=00:0C:29:D5:39:A0                    #MAC地址,不用修改

IPADDR=172.28.90.202                                 #设置新的IP

NETMASK=255.255.0.0

NETWORK=172.28.0.0

ONBOOT=yes

~

———————————————————————————————————

~

"ifcfg-eth0:2" 9L, 206C written

[root@rep1 network-scripts]# service network restart           #重启下网络服务

Shutting down interface eth0:                              [  OK  ]

Shutting down loopback interface:                          [  OK  ]

Bringing up loopback interface:                            [  OK  ]

Bringing up interface eth0:                                [  OK  ]

[root@rep1 network-scripts]# ifconfig                             #修改好后验证是否成功

eth0      Link encap:Ethernet  HWaddr 00:0C:29:D5:39:A0

inet addr:172.28.90.101  Bcast:172.28.255.255  Mask:255.255.0.0

inet6 addr: fe80::20c:29ff:fed5:39a0/64 Scope:Link

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:3131096 errors:0 dropped:0 overruns:0 frame:0

TX packets:101660 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:462925438 (441.4 MiB)  TX bytes:10829005 (10.3 MiB)

Interrupt:75 Base address:0x2000

eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:D5:39:A0

inet addr:172.28.90.201  Bcast:172.28.255.255  Mask:255.255.0.0

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

Interrupt:75 Base address:0x2000

eth0:2    Link encap:Ethernet  HWaddr 00:0C:29:D5:39:A0

inet addr:172.28.90.202  Bcast:172.28.255.255  Mask:255.255.0.0

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

Interrupt:75 Base address:0x2000

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:1427 errors:0 dropped:0 overruns:0 frame:0

TX packets:1427 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:3335045 (3.1 MiB)  TX bytes:3335045 (3.1 MiB)

[root@rep1 network-scripts]# ls

ifcfg-eth0    ifdown-ipsec   ifdown-tunnel  ifup-ipx     ifup-sl

ifcfg-eth0:1  ifdown-ipv6    ifup           ifup-isdn    ifup-tunnel

ifcfg-eth0:2  ifdown-isdn    ifup-aliases   ifup-plip    ifup-wireless

ifcfg-lo      ifdown-post    ifup-bnep      ifup-plusb   init.ipv6-global

ifdown        ifdown-ppp     ifup-eth       ifup-post    net.hotplug

ifdown-bnep   ifdown-routes  ifup-ippp      ifup-ppp     network-functions

ifdown-eth    ifdown-sit     ifup-ipsec     ifup-routes  network-functions-ipv6

ifdown-ippp   ifdown-sl      ifup-ipv6      ifup-sit

[root@rep1 network-scripts]#

————————————————

文链接:https://blog.csdn.net/lee244868149/article/details/38518635

相关文章

公众号