Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] Two IPs and two MACs on one NIC
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
WintermuteX
n00b
n00b


Joined: 29 Apr 2006
Posts: 40
Location: Germany

PostPosted: Tue Aug 29, 2017 6:52 pm    Post subject: [SOLVED] Two IPs and two MACs on one NIC Reply with quote

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. :)


Last edited by WintermuteX on Thu Aug 31, 2017 4:26 pm; edited 1 time in total
Back to top
View user's profile Send private message
Zucca
Veteran
Veteran


Joined: 14 Jun 2007
Posts: 1461
Location: KUUSANKOSKI, Finland

PostPosted: Tue Aug 29, 2017 7:53 pm    Post subject: Reply with quote

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.
_________________
..: Zucca :..

Code:
ERROR: '--failure' is not an option. Aborting...
Back to top
View user's profile Send private message
mike155
l33t
l33t


Joined: 17 Sep 2010
Posts: 989
Location: Frankfurt, Germany

PostPosted: Tue Aug 29, 2017 11:14 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
jburns
Veteran
Veteran


Joined: 18 Jan 2007
Posts: 1031
Location: Massachusetts USA

PostPosted: Wed Aug 30, 2017 2:25 am    Post subject: Reply with quote

http://www.practicalnetworking.net/series/packet-traveling/packet-traveling/ explains how packets travel on a network.
Back to top
View user's profile Send private message
WintermuteX
n00b
n00b


Joined: 29 Apr 2006
Posts: 40
Location: Germany

PostPosted: Wed Aug 30, 2017 5:36 am    Post subject: Reply with quote

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


I'm aware of that. ;) However this doesn't answer my question. :P

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):

Code:
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):

Code:
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:
Code:
ln -s /etc/init.d/net.lo /etc/init.d/net.macvlan0

And add it to the default boot:
Code:
rc-update add net.macvlan0 default
Back to top
View user's profile Send private message
SP2340
n00b
n00b


Joined: 01 Nov 2016
Posts: 50
Location: KeyStoneState

PostPosted: Thu Aug 31, 2017 12:48 pm    Post subject: Reply with quote

Glad to hear you found a way to make it work for you.
Please mark this thread as SOLVED. Thnx.
_________________
--
Regards
Robert

Smile, it increases your face value.
Back to top
View user's profile Send private message
WintermuteX
n00b
n00b


Joined: 29 Apr 2006
Posts: 40
Location: Germany

PostPosted: Thu Aug 31, 2017 4:27 pm    Post subject: Reply with quote

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. :)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum