打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Creating Virtual Network Adapters In CentOS |...

Creating Virtual Network Adapters In CentOS

Forward

So here’s the scenario, let’s say for the sake of argument that you have a CentOS linux box running with a single NIC, but you want to have 2 IP addresses assigned to this box (for whatever reason). The following is a step by step guide that will walk you through the process of setting that up.

Getting Started

First, you’ll need to determine the interface name of the network device being used.  For instance, if you’re running a wired ethernet card with a single port, the name is more than likely going to be eth0, if you’re using a wireless card it might be something like wlan0.  First thing you want to do is determine the interface name of this device.  An easy way to do this is to run the following command:

user@computer:$ ifconfig

You should see something similar to the following:

user@computer:$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:3D:2B:AD
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe3d:2bad/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2855541 errors:0 dropped:0 overruns:0 frame:0
TX packets:1205674 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:412143447 (393.0 MiB) TX bytes:539870133 (514.8 MiB)
Interrupt:75 Base address:0x2024

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:4968261 errors:0 dropped:0 overruns:0 frame:0
TX packets:4968261 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2009641198 (1.8 GiB) TX bytes:2009641198 (1.8 GiB)

In this scenario, eth0 is the network interface name and lo is the loopback name.  Now that we know eth0 is the one we want we’ll need to create a virtual device for it (aka. alias).

Create An Network Interface Alias

First, let’s change directory to the network-scripts folder.

user@computer:$ cd /etc/sysconfig/network-scripts/

Next, we’ll copy the ifcfg-<interface_name> to the alias name.

user@computer:$ cp ifcfg-eth0 ifcfg-eth0:0

In this example we are creating a single alias :0 however, you may create as many as you like.  Simply continue to copy the ifcfg-<interface_name> to the desired alias name (ie. ifcfg-eth0:1, ifcfg-eth0:2, etc).

Configure The Alias

Lastly, we need to configure the alias.  This is the step where you physically configure the interface to be static or use DHCP and set the routing information.

For arguments sake let’s configure it to be static.  Open the ifcfg-<interface_name> in the editor of your choice (ie. vi ifcfg-eth0) and set the following.

DEVICE=eth0:0BOOTPROTO=staticIPADDR=192.168.0.101NETMASK=255.255.255.0GATEWAY=192.168.0.1ONBOOT=yes

Modify each alias configuration file (ie. ifcfg-<interface_name> for each virtual adapter you add) making sure to change the DEVICE, IPADDR, NETMASK and GATEWAY to suit your network.

Once you’ve modified all of the alias configurations for all the aliases you are going to add, restart the network service and you’re good to go.

user@computer:$ service network restart

You can verify that the virtual interfaces are working by pinging each one individually of by running:

user@computer:$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:3D:2B:AD
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe3d:2bad/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2855541 errors:0 dropped:0 overruns:0 frame:0
TX packets:1205674 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:412143447 (393.0 MiB) TX bytes:539870133 (514.8 MiB)
Interrupt:75 Base address:0x2024

eth0:0 Link encap:Ethernet HWaddr 00:25:90:3B:BB:E4
inet addr:192.168.0.101 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:169 Memory:fb5e0000-fb600000

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:4968261 errors:0 dropped:0 overruns:0 frame:0
TX packets:4968261 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2009641198 (1.8 GiB) TX bytes:2009641198 (1.8 GiB)
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
kvm安装完全版 rhel6 - 虚拟化技术 - ChinaUnix.net
rhel6 下KVM的虚拟机网络配置
一张网卡配置一个以上的ip
linux下双网卡绑定技术实现负载均衡和失效保护
Linux 网络负载均衡的实现
和煦的点滴 ? 双网卡的机器,第一块网卡eth0,第二块网卡eth1,开启方法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服