# Shared connection with fixed IP with NetworkManager/dnsmasq

## simonbcn

My PC has a dual LAN motherboard, one connected to the Internet router and the other to a media player.

I want assign a fixed IP to media player and it allows access to Internet through the other LAN.

I'm using NetworkManager, dhclient and dnsmasq. I've gotten the player access to the Internet but not assign a fixed IP.

/etc/NetworkManager/NetworkManager.conf

```
[main]

plugins=keyfile

dns=dnsmasq

no-auto-default=*

```

/etc/NetworkManager/system-connections/VTEN (shared connection / link enp7s0)

```
[connection]

id=VTEN

uuid=1a887e17-8d8b-460f-8cda-8ca22e5b2f28

type=ethernet

permissions=

secondaries=

[ethernet]

mac-address=1C:6F:65:35:4E:24

mac-address-blacklist=

[ipv4]

dns-search=

may-fail=false

method=shared

[ipv6]

dns-search=

method=ignore

```

/etc/NetworkManager/system-connections/Internet (Internet / link enp8s0)

```
[connection]

id=enp8s0 (Internet)

uuid=39559adb-4564-423a-805e-d12229f22845

type=ethernet

autoconnect=true

permissions=

secondaries=

[ethernet]

mac-address=1C:6F:65:35:4E:34

mac-address-blacklist=

[ipv4]

dns-search=

method=auto

[ipv6]

dns-search=

method=ignore

```

To activate dnsmasq as dhcp server I have added this file with the MAC of media player and the IP that I want to assign it.

/etc/NetworkManager/dnsmasq.d/servidor-dhcp

```
interface=enp7s0

dhcp-range=192.168.2.2,192.168.2.50

dhcp-host=00:06:DC:89:74:36,192.168.2.2

```

/etc/dhcp/dhclient.conf

```
alias {

  interface "enp7s0";

  fixed-address 192.168.2.1;

  option subnet-mask 255.255.255.0;

  option broadcast-address 192.168.2.255;

  option domain-name-servers 127.0.0.1;

}

```

systemctl status -l NetworkManager

```
● NetworkManager.service - Network Manager

   Loaded: loaded (/usr/lib64/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)

   Active: active (running) since mar 2015-12-08 01:51:15 CET; 59s ago

 Main PID: 25570 (NetworkManager)

   CGroup: /system.slice/NetworkManager.service

           ├─25570 /usr/sbin/NetworkManager --no-daemon

           ├─25579 /sbin/dhclient -d -q -sf /usr/libexec/nm-dhcp-helper -pf /var/run/dhclient-enp8s0.pid -lf /var/lib/NetworkManager/dhclient-3382e7d4-c7a1-41a1-9b12-a7fa20bb3aa4-enp8s0.lease -cf /var/lib/NetworkManager/dhclient-enp8s0.conf enp8s0

           └─26336 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --pid-file=/var/run/NetworkManager/dnsmasq.pid --listen-address=127.0.0.1 --conf-file=/var/run/NetworkManager/dnsmasq.conf --cache-size=400 --proxy-dnssec --conf-dir=/etc/NetworkManager/dnsmasq.d

dic 08 01:51:21 localhost NetworkManager[25570]: <info>  Executing: /sbin/iptables --table filter --delete FORWARD --destination 10.42.0.0/255.255.255.0 --out-interface enp7s0 --match state --state ESTABLISHED,RELATED --jump ACCEPT

dic 08 01:51:21 localhost NetworkManager[25570]: <info>  Executing: /sbin/iptables --table filter --delete FORWARD --source 10.42.0.0/255.255.255.0 --in-interface enp7s0 --jump ACCEPT

dic 08 01:51:21 localhost NetworkManager[25570]: <info>  Executing: /sbin/iptables --table filter --delete FORWARD --in-interface enp7s0 --out-interface enp7s0 --jump ACCEPT

dic 08 01:51:21 localhost NetworkManager[25570]: <info>  Executing: /sbin/iptables --table filter --delete FORWARD --out-interface enp7s0 --jump REJECT

dic 08 01:51:21 localhost NetworkManager[25570]: <info>  Executing: /sbin/iptables --table filter --delete FORWARD --in-interface enp7s0 --jump REJECT

dic 08 01:51:21 localhost NetworkManager[25570]: <info>  Executing: /sbin/iptables --table filter --delete INPUT --in-interface enp7s0 --protocol udp --destination-port 67 --jump ACCEPT

dic 08 01:51:21 localhost NetworkManager[25570]: <info>  Executing: /sbin/iptables --table filter --delete INPUT --in-interface enp7s0 --protocol tcp --destination-port 67 --jump ACCEPT

dic 08 01:51:21 localhost NetworkManager[25570]: <info>  Executing: /sbin/iptables --table filter --delete INPUT --in-interface enp7s0 --protocol udp --destination-port 53 --jump ACCEPT

dic 08 01:51:21 localhost NetworkManager[25570]: <info>  Executing: /sbin/iptables --table filter --delete INPUT --in-interface enp7s0 --protocol tcp --destination-port 53 --jump ACCEPT

dic 08 01:51:26 localhost NetworkManager[25570]: <info>  startup complete

```

This is the result:

```
ip a                            

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 

.....

2: enp7s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000

    link/ether 1c:6f:65:35:4e:24 brd ff:ff:ff:ff:ff:ff

    inet 10.42.0.1/24 brd 10.42.0.255 scope global enp7s0

       valid_lft forever preferred_lft forever

    inet6 fe80::1e6f:65ff:fe35:4e24/64 scope link tentative 

       valid_lft forever preferred_lft forever

3: enp8s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000

    link/ether 1c:6f:65:35:4e:34 brd ff:ff:ff:ff:ff:ff

    inet 192.168.1.2/24 brd 192.168.1.255 scope global dynamic enp8s0

       valid_lft 86401sec preferred_lft 86401sec

    inet6 fe80::1e6f:65ff:fe35:4e34/64 scope link 

       valid_lft forever preferred_lft forever

```

The enp7s0 link and mediaplayer have a ¿random? IP ¿assigned by NetworkManager?. Neither dnsmasq (dhcp) nor dhclient (with enp7s0) do their job.

----------

