Two IP address on one network adapter over macvlan

Posted on

A server stack is the collection of software that forms the operational infrastructure on a given machine. In a computing context, a stack is an ordered pile. A server stack is one type of solution stack — an ordered selection of software that makes it possible to complete a particular task. Like in this post about Two IP address on one network adapter over macvlan was one problem in server stack that need for a solution. Below are some tips in manage your linux server when you find problem about linux, networking, vlan, , .

On Debian Linux dist I need two IP address with different mac address. On each of them one server will run on port 80. So i need something like this:

ip: 192.168.2.1 mac: xx:xx:xx:10:xx:xx
ip: 192.168.2.2 mac: xx:xx:xx:90:xx:xx

And then start two http servers each listen one ip address.

Already have eth0 setup to proper ip address and i tried to setup virtual network adapter via macvlan:

ip link add link eth0 name vlan0 type macvlan mode private
ip address add 192.168.2.2 dev vlan0 
ip link set dev vlan0 address xx:xx:xx:90:xx:xx
ip link set dev vlan0 up

When i enter url 192.168.2.2 i get same page as 192.168.2.1. So basically everything on port 80 is routed to that server.
I also tried all different modes of macvlan but result is always same.

What am i doing wrong? Is this even possible with macvlan or i need different approach?

well, that is not a big deal as you can easily to do this by creating virtual interfaces on single physical interface.

you can simply do this as follow:

ifconfig wlan0:if1 <IP> <NM>
ifconfig wlan0:if2 <IP> <NM>

I used ifconfig but you can use ip link the same way.

alternatively you can create the interfaces file entries manually as follow:

 vi /etc/sysconfig/network-scripts/ifcfg-wlan0

  DEVICE=wlan0
  BOOTPROTO=static
  IPADDR=192.168.1.2
  NETMASK=255.255.255.0
  ONBOOT=yes

  vi /etc/sysconfig/network-scripts/ifcfg-wlan0:1

  DEVICE=wlan0:1
  BOOTPROTO=static
  IPADDR=192.168.1.3
  NETMASK=255.255.255.0
  ONBOOT=yes

However, it is not best practice to assign the same subnet/IP to virtual interfaces, I’d suggest to use separate vlan like 192.168.2.x

It sounds like what you want to do is MAC spoofing. In your case, you should do as ostendali suggested and create two virtual interfaces and then spoof the mac on them. That is a pretty simple thing to do. There are some simple instructions here.

Though it is a little unclear, I’ll take a stab in the dark here. You also mention that you want separate servers running on the different interfaces and that they will be using port 80. Sounds like you are trying to host multiple websites on one server. Apache2 is a pretty popular choice so here is a walkthrough for hosting multiple sites. Good Luck!

Leave a Reply

Your email address will not be published. Required fields are marked *