为Linux(CentOS)配置多个IP地址

有时候为了特殊的需要会为一台服务器配置多个IP地址,那么如何在一块网卡上配置多个IP地址呢,其实很简单,新创建一个网络接口配置文件即可。

创建网络接口配置文件

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0:1 //重新创建一个接口文件

编辑该网络接口配置文件

//添加如下内容

DEVICE=eth0
BOOTPROTO=static
HWADDR=00:0C:29:0D:4C:02
ONBOOT=yes
IPADDR=172.16.78.145
NETMASK=255.255.255.0
GATEWAY=172.16.78.1

重启网络服务

[root@localhost ~]# service network restart

验证

[root@localhost ~]# ifconfig 


eth0      Link encap:Ethernet  HWaddr 00:0C:29:0D:4C:02
          inet addr:172.16.78.59  Bcast:172.16.78.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe0d:4c02/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:921824 errors:0 dropped:0 overruns:0 frame:0
          TX packets:114895 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:175737868 (167.5 MiB)  TX bytes:36500036 (34.8 MiB)
          Interrupt:75 Base address:0×2000

eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:0D:4C:02
          inet addr:172.16.78.145  Bcast:172.16.78.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:75 Base address:0×2000

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

修改成功!

声明: 本文采用 BY-NC-SA 协议进行授权. 转载请注明转自: 为Linux(CentOS)配置多个IP地址
  1. No comments yet.
  1. No trackbacks yet.

Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).