Two NICs problem

Kernels & Hardware, configuring network, installing services

Two NICs problem

Postby ChrisPL » 2018-04-17 21:17

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.
ChrisPL
 
Posts: 14
Joined: 2017-09-10 20:16

Re: Two NICs problem

Postby p.H » 2018-04-18 12:11

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.
p.H
 
Posts: 423
Joined: 2017-09-17 07:12

Re: Two NICs problem

Postby ChrisPL » 2018-04-24 19:03

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.
ChrisPL
 
Posts: 14
Joined: 2017-09-10 20:16

Re: [SOLVED]Two NICs problem

Postby p.H » 2018-04-24 21:03

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 ?
p.H
 
Posts: 423
Joined: 2017-09-17 07:12

Re: [SOLVED]Two NICs problem

Postby ChrisPL » 2018-04-25 21:22

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.
ChrisPL
 
Posts: 14
Joined: 2017-09-10 20:16

Re: [SOLVED]Two NICs problem

Postby p.H » 2018-04-26 06:53

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.
p.H
 
Posts: 423
Joined: 2017-09-17 07:12

Re: [SOLVED]Two NICs problem

Postby ChrisPL » 2018-04-26 20:45

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.
ChrisPL
 
Posts: 14
Joined: 2017-09-10 20:16

Re: [SOLVED]Two NICs problem

Postby bw123 » 2018-04-26 22:01

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.
User avatar
bw123
 
Posts: 3184
Joined: 2011-05-09 06:02
Location: TN_USA

Re: [SOLVED]Two NICs problem

Postby arzgi » 2018-04-27 06:14

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.
arzgi
 
Posts: 282
Joined: 2008-02-21 17:03
Location: Finland

Re: [SOLVED]Two NICs problem

Postby p.H » 2018-04-28 12:15

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.
p.H
 
Posts: 423
Joined: 2017-09-17 07:12

Re: [SOLVED]Two NICs problem

Postby ChrisPL » 2018-05-01 04:38

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.
ChrisPL
 
Posts: 14
Joined: 2017-09-10 20:16

Re: [SOLVED]Two NICs problem

Postby arzgi » 2018-05-01 06:31

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.
arzgi
 
Posts: 282
Joined: 2008-02-21 17:03
Location: Finland

Re: [SOLVED]Two NICs problem

Postby ChrisPL » 2018-05-01 18:56

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.
ChrisPL
 
Posts: 14
Joined: 2017-09-10 20:16

Re: [SOLVED]Two NICs problem

Postby p.H » 2018-05-02 21:31

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.
p.H
 
Posts: 423
Joined: 2017-09-17 07:12

Re: Two NICs problem

Postby ChrisPL » 2018-07-25 04:35

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.
ChrisPL
 
Posts: 14
Joined: 2017-09-10 20:16

Next

Return to System configuration

Who is online

Users browsing this forum: No registered users and 5 guests

fashionable