# Static IP Addresses and a Laptop with Two Network Cards

## mojosam

My laptop has a wired ethernet card and a wireless card. Both are currently connected to my router. In this situation, is it normal for the laptop to have one or two IP addresses?

I am also trying to assign static IP addresses to all of my devices. I thought I'd be clever and assign all wired devices an address in the 192.168.1.11 to .19 range. I'd give wireless devices an address in the 192.168.1.31 to .39 range.

I would like my Gentoo laptop to have the addresses 192.168.1.13 and .33. Am I being excessively anal-retentive?

Here is my /etc/conf.d/net file:

```
config_enp9s0="192.168.1.13 netmask 255.255.255.0"

routes_enp9s0="default via 192.168.1.1"

dns_servers_enp9s0="192.168.1.1 208.67.222.222 208.67.220.220"

config_wlp12s0b1="192.168.1.33 netmask 255.255.255.0"

routes_wlp12s0b1="default via 192.168.1.1"

dns_servers_wlp12s0b1="192.168.1.1 208.67.222.222 208.67.220.220"

# Prefer wpa_supplicant over wireless-tools

modules="wpa_supplicant"
```

I gave my router the MAC addresses of the boards and told it to assign them the same way you see above. I.e., enp9s0=192.168.1.13 and wlp12s0b1=192.168.1.33

When only the wifi is connected, the router gives it the .13 address (incorrect) instead of .33. Am I correct in assuming that the router is at fault here and not Gentoo?

When both boards are connected, the router gives the wired board the .13 address (correct), but it gives the wifi board a .51 address! (The range .51 to .59 I'm leaving for DHCP.)

Does my /etc/conf.d/net look correct? Am I trying to do something reasonable? If so, how do I fix it?Last edited by mojosam on Tue Sep 10, 2019 7:25 am; edited 1 time in total

----------

## alamahant

Hi 

You can not have two ifaces with default gateway assigned active simultaneously.But further than that If you only have the wifi active and it gets assigned the ethernet ip address then it is NOT alright.

Use only one of them or remove the 

"default via"

in one of them...

 :Smile: 

----------

## mojosam

```
You can not have two ifaces with default gateway assigned active simultaneously.
```

Oh. I didn't know what "default" did. I just copied the text from the Handbook and repeated it for the second card.

I just removed this entire line from my /etc/conf.d/net file and rebooted:

```
routes_wlp12s0b1="default via 192.168.1.1"
```

Was that the correct thing to do? I noticed that this change had no effect on the IP addresses. The wired card is still .13 (correct), and the wifi card is still .51 (incorrect).

Ultimately, I will probably want the wired port to be the one in use if it's plugged in. Otherwise use the wireless. I discovered the ifplugd command and was planning to use it. I didn't want to overcomplicate my question at first.

There's nothing wrong with having two active network cards, right?

----------

## NeddySeagoon

mojosam,

The default route is a route of last resort. Everything that does not match anything else in the output of 

```
route
```

 is sent there.

Its your system dealing with traffic it does not know how to route, so it sends it to a host (your router) that does.

This process is repeated as required.

Your router can't route it either, so it sends it to your ISP ... and so on.

As you can have at most, one default route, if that is assigned to your wired interface, when only WiFi is working, you won't be able to get to the internet because your default rout will be over wired, which is not in use.

----------

## mojosam

 *Quote:*   

> As you can have at most, one default route, if that is assigned to your wired interface, when only WiFi is working, you won't be able to get to the internet because your default rout will be over wired, which is not in use.

 

OK. How do I fix this? I couldn't find anything in the documentation that specifically addresses this issue. It seems to me that I need one line that uses the word "default" and mentions 192.168.1.1 but doesn't mention either NIC.

I'm also guessing that the other lines are fine as written.

----------

## Jaglover

In my laptop I use wicd, it manages the interfaces. Both wired and wireless have same static IP address when at home. When traveling I can use wicd GUI applet to search and connect to wireless access points.

----------

## NeddySeagoon

mojosam,

You don't use a static setup at all.

Why do you need a static network setup?

----------

## mojosam

 *Quote:*   

> Both wired and wireless have same static IP address when at home.

 

What I want to do is use the wired connection for full-privilege network access but use wireless to connect to the guest network. Most of the time I'd use wireless. Just keeps things more secure.

 *Quote:*   

> You don't use a static setup at all.

 

Just because it isn't common doesn't mean it shouldn't be done.

 *Quote:*   

> Why do you need a static network setup?

 

Part of it is convenience. I used to use a lot of shell scripts on a job I used to have. It was so convenient to just hard-code the IP addresses into the scripts. Also, my printer goes to sleep and my phone goes onto airplane mode when I leave home. When I come back home, sometimes their IP addresses collide.

----------

## NeddySeagoon

mojosam,

```
config_enp9s0="192.168.1.13 netmask 255.255.255.0"

...

config_wlp12s0b1="192.168.1.33 netmask 255.255.255.0"
```

That's two IPs is the same network. How is it split into guest and full privilege?

My WiFi in on 192.168.54.0/24, my protected wired network is on 192.168.100.0/24

WiFi cannot initiate connections to wired.

Both have a small range of addresses reserved for allocation by dhcp.

All the untrusted equipment is on 192.168.54.0/24 regardless of it being WIFi or not.

The split is controlled by my Gentoo/Shorewall router.

----------

## mojosam

 *Quote:*   

> That's two IPs is the same network. How is it split into guest and full privilege?

 

The wired Ethernet is full privilege. I do have a wifi AP that connects to the full privilege network, but I'm not currently planning to use it with this machine.

I also have a wifi AP set up as a Guest network. That's the network I plan to connect to most of the time. On the occasions when this machine needs full network access, then I will plug it into the wired Ethernet. (I was thinking of using the ifplugd command for this, unless there is a better way.)

----------

## NeddySeagoon

mojosam,

Fully static and more than one interface cannot work due to the one default route limit.

Fully static and either or works. You manually bring up the interface you want to use.

You can bring up both interfaces then run a script to set the default route correctly too.

This can be automated too.  ifplugd should work. I've never needed it.

I have a hard separation between my trusted and untrusted networks. Nothing is ever on both, there being no point in separation, if there is a bridge.

Once something is untrusted, it can only be moved to trusted if its reinstalled.

TVs, Android devices etc, are only ever untrusted.

Trusted wifi is an oxymoron. You need to run your own encryption over Wifi to be able to trust it. 

Maybe I'm more paranoid than you are :)

----------

## UberLord

 *mojosam wrote:*   

> I gave my router the MAC addresses of the boards and told it to assign them the same way you see above. I.e., enp9s0=192.168.1.13 and wlp12s0b1=192.168.1.33

 

Silly question time!

If the router is handing out IP addresses based on MAC address, why aren't you using DHCP for clients?

Try disabling all net.* services and just enable dhcpcd.

See the links in my signature for more details.

----------

## mojosam

I surrender. I'm going back to DHCP.

The whole reason I'm using Gentoo is to try to learn more about Linux than I can get from running Ubuntu. I thought this static IP address thing would be doable. I did it 11 years ago on BSD. That was dead-simple. Maybe somebody had already done the heavy lifting on that network, or maybe BSD is fundamentally different. In any case, this static IP business is a MUCH deeper hole than I thought I was getting into.

 *Quote:*   

> If the router is handing out IP addresses based on MAC address, why aren't you using DHCP for clients?

 

I didn't realize that was independent of the static IP issue. So that solves part of my problem anyway.

So now to fix things, I need to unwind my brain. It looks like Netifrc and DHCPCD are incompatible. I changed my /etc/conf.d/net to:

```
# For DHCP

config_enp9s0="dhcp"

config_wlp12s0b1="dhcp"

# Prefer wpa_supplicant over wireless-tools

modules="wpa_supplicant"
```

But isn't this file only used with Netifrc? So does its existence force the system to use Netifrc instead of DHCPCD?

My /etc/wpa_supplicant/wpa_supplicant.conf file is:

```
# Allow users in the 'wheel' group to control wpa_supplicant

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel

# Make this file writable for wpa_gui / wpa_cli

update_config=1

# Adding this line so only root can read the WPA configuration.

ctrl_interface_group=0

network={

   ssid="NetworkGuest2.4GHz"

   psk="[redacted]"

}
```

Do the ctrl_interface and ctrl_interface_group lines conflict?

The netstat -rn command returns the following. Does it look OK?

```
Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 enp9s0

0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 wlp12s0b1

192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 enp9s0

192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 wlp12s0b1

```

----------

## NeddySeagoon

mojosam,

```
Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 enp9s0

0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 wlp12s0b1 
```

 *Chance Card wrote:*   

> Go to Jail
> 
> Go directly to jail
> 
> Do not pass Go
> ...

 

You must not have more that one default route at a time.

In the above, only the default over wlp12s0b1 will ever be used.

----------

## mojosam

 *Quote:*   

> You must not have more that one default route at a time.
> 
> In the above, only the default over wlp12s0b1 will ever be used.

 

That's what I was afraid of. It looks like the old route is still active. Where do I undo that?

----------

## NeddySeagoon

mojosam,

That all depends on where/how its being set.

----------

## UberLord

 *NeddySeagoon wrote:*   

> mojosam,
> 
> ```
> Kernel IP routing table
> 
> ...

 

Respectfully, I disagree.

You can have as many default routes as you like. Infact, in this situation, dhcpcd would install two default routes.

The key is that only the default route with the lowest metric will be used. The rest will be ignored.

dhcpcd will give wireless a higher metric than wired, so wired would be preferred by default.

Check the output of `ip r` to see the important metric.

----------

## mojosam

 *Quote:*   

> You can have as many default routes as you like. Infact, in this situation, dhcpcd would install two default routes.
> 
> The key is that only the default route with the lowest metric will be used. The rest will be ignored.

 

I remember reading that somewhere.

In this case, I was worried that the route was leftover from when I was trying to assign static IP addresses. You're saying that dhcpd probably did this?

ip r tells me that the wired card has a metric of 202 and the wireless card has a metric of 303.

----------

## UberLord

So there we go - wired will be preferred over wireless.

----------

## mojosam

OK. It looks like I have returned my system to a workable state after my static IP misadventure. Thanks to all who talked me out of it and helped in other ways.

----------

## NeddySeagoon

UberLord,

Thank you for the correction.

----------

