Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Two NICs problem

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
ChrisPL
Posts: 14
Joined: 2017-09-10 20:16

Two NICs problem

#1 Post by ChrisPL »

I read many articles how to configure two NICs on one PC with static addresses. Is it possible to do that when IP address can be obtained via DHCP for both networks? The problem is to get access to two networks: from first NIC - to local network, and through second NIC to outside world.
Last edited by ChrisPL on 2018-07-25 04:28, edited 2 times in total.

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: Two NICs problem

#2 Post by p.H »

A usual problem is conflicting options such as router/gateway and DNS provided by the DCHP servers.
If only one DHCP server provides these information, then there is no conflict. Otherwise, It depends on the network management service and DHCP client used.

The network management service may allow to define precedence amongst interfaces, so that if an option is provided on both interfaces then the value on the interface with higher precedence is used.

Or the DHCP client software may be configured to not request router and DNS options on one interface (usually on the local network side), but some DHCP servers are tricky and send the option anyway. Or the DHCP client software may be configured to ignore some options contained in replies received on one interface.

ChrisPL
Posts: 14
Joined: 2017-09-10 20:16

Re: Two NICs problem

#3 Post by ChrisPL »

I solved the problem this way and it is working. Below, there is my interfaces file. Of course, I added table rt2 to routing tables before.

Code: Select all

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eno1
iface eno1 inet dhcp

# The secondary network interface
auto enp2s2
iface enp2s2 inet dhcp
post-up ip route add 192.168.0.0/24 dev enp2s2 src 192.168.0.120 table rt2
post-up ip route add default via 192.168.0.1 dev enp2s2 table rt2
post-up ip rule add from 192.168.0.120/32 table rt2
post-up ip rule add to 192.168.0.120/32 table rt2
I don't know whether it is proper or elegant but it does do what I want. Both NICs fetch IP address by DHCP but the second is quasi static. My router offers either DHCP or static addresses but not both at one time so I assigned MAC address of enp2s2 interface to IP 192.168.0.120 on the router what it allows.

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: [SOLVED]Two NICs problem

#4 Post by p.H »

What is the point in using DHCP if you're setting static routes ? It won't work on another network.
Why not use a fully static configuration for that interface ?

ChrisPL
Posts: 14
Joined: 2017-09-10 20:16

Re: [SOLVED]Two NICs problem

#5 Post by ChrisPL »

The reason is that only one PC has two NICs. The rest of home network receives IP through DHCP. The next reason is that my ISP has given me two external IPs and thus I can split network traffic increasing overall bandwidth. The third one is that this PC is connected to the world without router and the rest of network through one but I wanted to use sharing capabilities in home network. Besides that I didn't want to bother with static addresses for other clients (PCs, laptops, smart-phones etc.).
I really didn't know how to get this configuration working so I did it this way. Maybe there is better way.

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: [SOLVED]Two NICs problem

#6 Post by p.H »

I meant "what is the point in using DHCP on this interface (enp2s2) of this computer" ?
Your reply does not justify this choice at all. The only reason I see would be that DCHP provides some dynamic parameter that cannot be set statically.
Otherwise, you can configure this interface statically and use DHCP with all other interfaces and devices in your network.

ChrisPL
Posts: 14
Joined: 2017-09-10 20:16

Re: [SOLVED]Two NICs problem

#7 Post by ChrisPL »

I don't think I could configure enp2s2 statically because my router is configured as DHCP and this is suitable for the rest of my home network. I couldn't manage to declare static address on this interface while router is DHCP server. It cannot serve both as DHCP and allow static addresses.

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: [SOLVED]Two NICs problem

#8 Post by bw123 »

ChrisPL wrote:I don't think I could configure enp2s2 statically because my router is configured as DHCP and this is suitable for the rest of my home network. I couldn't manage to declare static address on this interface while router is DHCP server. It cannot serve both as DHCP and allow static addresses.
Most routers will have a range for dhcp addresses, usually 100, so just assigning a static address of 120 would usually be outside of this range.

What router brand/model is it? That's good to know that you can't use dhcp and static addressing at the same time, and might help people in the future.
resigned by AI ChatGPT

arzgi
Posts: 1185
Joined: 2008-02-21 17:03
Location: Finland
Been thanked: 31 times

Re: [SOLVED]Two NICs problem

#9 Post by arzgi »

bw123 wrote:
ChrisPL wrote:I don't think I could configure enp2s2 statically because my router is configured as DHCP and this is suitable for the rest of my home network. I couldn't manage to declare static address on this interface while router is DHCP server. It cannot serve both as DHCP and allow static addresses.
Most routers will have a range for dhcp addresses, usually 100, so just assigning a static address of 120 would usually be outside of this range.
.
Beside that, even most consumer grade routers let you assign static addresses to MAC:s. Check your router documentation.

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: [SOLVED]Two NICs problem

#10 Post by p.H »

ChrisPL wrote:I don't think I could configure enp2s2 statically because my router is configured as DHCP and this is suitable for the rest of my home network. I couldn't manage to declare static address on this interface while router is DHCP server. It cannot serve both as DHCP and allow static addresses.
Static assignment on the host is not the same as dynamic assignment with a fixed reserved address by the DHCP server.

You don't need special configuration on the router or the DHCP server to use static configuration on a host. Having a DHCP server on the network does not mean that all hosts must use DHCP. The main purpose of a router is to forward packets, not assign DHCP leases. It does not matter whether a packet has an IP address that was assigned statically or by DHCP.

The only problem is to avoid to assign as static address that could be assigned by DHCP. As others pointed out, most DHCP server serve addresses in a range which does not cover all the subnet. So assigning a static address outside the DHCP range should be fine.

ChrisPL
Posts: 14
Joined: 2017-09-10 20:16

Re: [SOLVED]Two NICs problem

#11 Post by ChrisPL »

No, my router (Dlink DIR-100) can't do that. I tried static address outside specified range for DHCP clients and system failed to configure this NIC. Still, this solution seems to be the one.

arzgi
Posts: 1185
Joined: 2008-02-21 17:03
Location: Finland
Been thanked: 31 times

Re: [SOLVED]Two NICs problem

#12 Post by arzgi »

ChrisPL wrote:No, my router (Dlink DIR-100) can't do that. I tried static address outside specified range for DHCP clients and system failed to configure this NIC. Still, this solution seems to be the one.
I greatly doubt that. I even tried to load the manual, but Dlink's page used captha, that did not work in my browser (QupZilla).

I have not seen any router, that won't let you change DHCP address range. If static address outside this range does not work, you have configured NIC wrong.

My solution, /etc/network/interfaces/ :

Code: Select all

#DHCP:

allow-hotplug eth0
iface eth0 inet dhcp

#static:

allow-hotplug eth1
iface eth1 inet static
address 192.168.1.33
netmask 255.255.255.0
gateway 192.168.1.1
And here DHCP range is 2-20, for phones etc. All in same subnet.

ChrisPL
Posts: 14
Joined: 2017-09-10 20:16

Re: [SOLVED]Two NICs problem

#13 Post by ChrisPL »

My interfaces looks like this:

Code: Select all

# The primary network interface
auto eno1
iface eno1 inet dhcp

# The secondary network interface
auto enp2s2
iface enp2s2 inet dhcp
#iface enp2s2 inet static
#address 192.168.0.20
#netmask 255.255.255.0
#gateway 192.168.0.1
post-up ip route add 192.168.0.0/24 dev enp2s2 src 192.168.0.120 table rt2
post-up ip route add default via 192.168.0.1 dev enp2s2 table rt2
post-up ip rule add from 192.168.0.120/32 table rt2
post-up ip rule add to 192.168.0.120/32 table rt2
#post-up ip route add 192.168.0.0/24 dev enp2s2 src 192.168.0.20 table rt2
#post-up ip route add default via 192.168.0.1 dev enp2s2 table rt2
#post-up ip rule add from 192.168.0.20/32 table rt2
#post-up ip rule add to 192.168.0.20/32 table rt2
Hashed lines for enp2s2 were active with static address and it didn't work. DHCP address range is 100 to 199. 120 is reserved for MAC of my second NIC.

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: [SOLVED]Two NICs problem

#14 Post by p.H »

ChrisPL wrote:No, my router (Dlink DIR-100) can't do that.
This does not make sense. Static configuration does not involve the router in any way. It is purely local configuration.
ChrisPL wrote: I tried static address outside specified range for DHCP clients and system failed to configure this NIC.
How did it fail ? What happened ?
ChrisPL wrote:My interfaces looks like this:
- You must not define a gateway option. This option creates a default route in the main routing table, but one default route is already provided by DHCP on the other interface and multiple default routes in the same routing table make no sense.
- The "ip rule add to" command is useless and makes no sense. Local addresses are always routed according to the higher-priority "local" routing table.

ChrisPL
Posts: 14
Joined: 2017-09-10 20:16

Re: Two NICs problem

#15 Post by ChrisPL »

With configuration as above there still is a problem with DNS. After a short while the system is up I can't browse the web nor can I ping using URL. Then I have to switch off the "local" NIC.
I need two NICs with one only for sharing purposes and other for all other outgoing and incoming traffic.

arzgi
Posts: 1185
Joined: 2008-02-21 17:03
Location: Finland
Been thanked: 31 times

Re: Two NICs problem

#16 Post by arzgi »

ChrisPL wrote:With configuration as above there still is a problem with DNS. After a short while the system is up I can't browse the web nor can I ping using URL. Then I have to switch off the "local" NIC.
I need two NICs with one only for sharing purposes and other for all other outgoing and incoming traffic.
You were given many hints.

If your ISP gives 2 addresses, it does not mean you have to use both. If configuring seems overhelming despite all the help you got, maybe remove the second NIC. If that's not option, read the thread through.

Post Reply