# [SOLVED] Two IPs and two MACs on one NIC

## WintermuteX

Hello,

I searched on the net for an answer to this problem, but couldn't find one:

I have one NIC and I'm unable to add another one, but I need two different MACs on this NIC and two IPs, each one bound to the other MAC.

NIC1 -> MAC1 -> IP1

NIC1 -> MAC2 -> IP2

Both IPs are in the same subnet and should use the same router, I bound different services on each IP for various reasons.

Those settings must also be persistant to reboots.

If somebody could help me I would be very happy.  :Smile: Last edited by WintermuteX on Thu Aug 31, 2017 4:26 pm; edited 1 time in total

----------

## Zucca

Two ips per nic is possible, but I don't think two macs are possible unless you have two ports on your nic or if you use only one of the ips at the time (changing the mac dynamically upon each ethernet hotplug).

Either way. I'm also interested if this is possible. I might need that feature also in the future.

----------

## mike155

You can achieve that using a bridge: create an internal bridge "br0", and connect it to NIC1. This will give you an interface "br0" with its own MAC address. You can assign IP1 to that interface. Now add a dummy or tap interface to the bridge. It will give you a second interface with its own MAC address. You can assign IP2 to it. You can add as many tap or dummy interfaces as you want, which will give you as many distinct MAC and IP addresses as you want.

----------

## jburns

http://www.practicalnetworking.net/series/packet-traveling/packet-traveling/ explains how packets travel on a network.

----------

## WintermuteX

 *jburns wrote:*   

> http://www.practicalnetworking.net/series/packet-traveling/packet-traveling/ explains how packets travel on a network.

 

I'm aware of that.  :Wink:  However this doesn't answer my question.  :Razz: 

 *bug_report wrote:*   

> You can achieve that using a bridge: create an internal bridge "br0", and connect it to NIC1. This will give you an interface "br0" with its own MAC address. You can assign IP1 to that interface. Now add a dummy or tap interface to the bridge. It will give you a second interface with its own MAC address. You can assign IP2 to it. You can add as many tap or dummy interfaces as you want, which will give you as many distinct MAC and IP addresses as you want.

 

This helped me looking in the right direction, but I solved it in another way at the end. Thanks for pointing me in the right direction. I simply used the wrong keywords at the searchengines and your answer helped me when I was looking deeper into your solution. I ended up with defining a MAC-VLAN.

My configuration in /etc/conf.d/net now looks something like that (for others looking for such a solution):

```
config_enp0s31f6="10.20.0.200/24"

routes_enp0s31f6="default via 10.20.0.1"

rc_net_macvlan0_need="net.enp0s31f6"

macvlan_macvlan0="enp0s31f6"

mode_macvlan0="private"

config_macvlan0="10.20.0.201/24"

mac_macvlan0="aa:bb:cc:dd:ee:f1"
```

If you define more than one macvlan you might want to switch mode "private" to "bridge" if there is a lot of traffic between the macvlans, so they never leave the PHY only to be directed back by your switch.

In my use case this is not needed, therefor only one macvlan for now.

You need to compile MAC-VLAN support into the kernel for this to work (I hadn't it configured):

```
Device Drivers -> Network device support -> Network core driver support -> MAC-VLAN support
```

Then simply start it like any other interface by linking the init script:

```
ln -s /etc/init.d/net.lo /etc/init.d/net.macvlan0
```

And add it to the default boot:

```
rc-update add net.macvlan0 default
```

----------

## SP2340

Glad to hear you found a way to make it work for you.

Please mark this thread as SOLVED.  Thnx.

----------

## WintermuteX

 *SP2340 wrote:*   

> Glad to hear you found a way to make it work for you.
> 
> Please mark this thread as SOLVED.  Thnx.

 

You are absolutely right, I forgot about it. Sorry.  :Smile: 

----------

