# how static IP in systemd

## pmam

Hi,

I am quite new in gentoo and just installed gnome/systemd.

I emerged NetworkManager.service and at the moment it is working in dhcp mode - 

I prefer to switch to static IP - I do know how to do it in OpenRC but need your advise regarding systemd.

----------

## Marlo

try this:

 */etc/systemd/system/static-network.service wrote:*   

> 
> 
> [Unit]
> 
> Description=Static network service
> ...

 

enp5s0 is my network cart. <use your own networknumbers>

----------

## pmam

Marlo Hi,

As I noted in my post I am new in gentoo...   :Very Happy: 

I understand that I should change to my network name card and to my IP address but -  

please explain me what I should do with this text?

I enabled NetworkManager.service -  Static IP is not part of it?   

Thanks

----------

## elmar283

Might be a little late but better late then never.

First I don't know wether you could set-up a static network with networkmanager.

But it would be strange if it couldn't be done.

If you want the network always be the same then you do not have the need fore networkmanager.

You can then open a terminal and type this:

```

cd /etc/systemd/system

nano -w static-network.service 

```

Now fill in the part of the other answer.

Then after your done type ctrl + o and ctrl + x.

then type:

```

chmod +x static-network.service 

systemctl enable static-network.service

systemctl start static-network.service

```

And finaly to check if it works:

```

ifconfig

```

If you are not a root user you might have to use sudo or login as root.

Hope this answers your question.

----------

## comprookie2000

You should be able to set it up with nm-applet under gnome

settings => network => wired then click on the gear * bottom right => ipv4 => Addresses => Manual

----------

## pmam

Dear elmar283 & comprookie2000,

 *Quote:*   

> Might be a little late but better late then never. 

 

Yes, a little bit  late   :Wink:   However still helpful tips for others and for me for the next trying of systemd.  

Due to some problems I had faced with systemd, I switched to Open-RC but at the moment reconsidering to try it again - 

I quite liked Gnome/Systemd. Is Gentoo's systemd has improved lately?

Thanks

----------

## elmar283

If you might want to try an network on systemd without NetworkManager, I just figured that out yesterday:

https://forums.gentoo.org/viewtopic-t-995866-highlight-systemd+wlp3s0.html

----------

## gcyoung

I have used the above Unit on several computers for a long while with no problems. Recently, however, after a fresh gentoo installation, it has failed to work: --on the new  setup only, it continues to function on two other machines.

After  booting, "systemctl status static-network.service" produces the following:-

                       "Loaded: loaded( /etc/systemd/system/static-network.service; enabled; vendor preset; disabled)"

If I 'restart' the unit it sets up my network as I intended. I do not understand the significance of 'vendor preset' , and would be grateful for an explanation. It is apparent that the unit is loading, but failing to act, so presumably something is missing, but I cannot fathom what that could be.

I am using kernel-4.9.16-gentoo

----------

## axl

just.. cool kernel parameters you could try:

ip=${my_ip}:${router_ip}:${nfs_root_ip_not_that_it_matters}:${netmask}:${hostname}:${interface}:${dns1}:${dns2} 

ip=192.168.23.23:192.168.0.1:192.168.0.2:255.255.0.0:somehost:eth0:8.8.8.8:8.8.4.4 

did you know your kernel does that?

----------

## gcyoung

I tried axl's  suggestion but it didn't work. I think because eth0 is changed to enps07  later in the booting process. Also, my ethernet card is started by a module, which dmesg shows as not starting until near the end of the boot process.

It was all so simple before systemd came along.  Just two lines of code would do!

----------

## Zucca

I use systemd-networkd on my systemd PC.

The documentation on the wiki is poor a the moment.

This is what I have:

```
[Match]

Name=ib0

 

[Network]

Description=IP over InfiniBand

LinkLocalAddressing=no

Address=10.0.10.2/28

Gateway=10.0.10.1

DNS=10.0.10.1

[Address]

Address=10.0.10.2/28

Broadcast=10.0.10.15
```

And for DHCP:

```
[Match]

Name=ethmb0

 

[Network]

DHCP=yes
```

Also read systemd-networkd man pages for more.

I hope this helped even though the options get pretty confusing when you dig deeper to the man pages... At least the first example I gave work here.

----------

## gcyoung

Thanks Zucca. Your contribution made me aware that there is a man page for systemd networking! I think now that I have a better understanding of systemd's intentions concerning ethernet configuration!  I don't think this procedure or a manual was available when I first swapped to systemd.

Anyway I have set up a *.network file in "/etc/systemd/network" similar to yours, enabled systemd-networkd.service and  all is now working as I intended.

----------

## Xootneg

elmar283 and Mario's steps did not work for me until I added the following three steps:

1. Change resolve.conf into a standard file instead of a shortcut file in /etc. 

2. Remove (un-emerge) BOTH dhcp & dhcpcd. Because I removed dhcp & dhcpcd completely, if my new Internet connection did not work I would have no Internet connection to download dhcp & dhcpcd to get my ORIGINAL dhcp Internet connection back. So DO MAKE SURE as an insurance policy, and BEFORE you remove dhcp & dhcpcd, to have the latest copies of dhcp & dhcpcd in /usr/portage /distfiles in order to re-emerge them without needing the Internet. Of course this is only necessary if your static connection did not work in order to revert to the old dhcp connection.

At the first when I had everything configured I issued the following commands:

```
# systemctl enable static-network.service

# systemctl start static-network.service
```

Then I brought up Firefox and my connection was now working with my static ip.   :Smile:  Then I rebooted and the network was dead.   :Crying or Very sad:  That is why you should save the copies of dhcp & dhcpcd into /usr/portage/distfiles. Adding these 3 steps from this post fixed it.

Remove dhcp and dhcpcd if you are using both or whichever one[s] you are using:

```
# emerge -Ca dhcp & dhcpcd
```

3. I did not use the name of my network card [cart] which did not work, I used the name found in the output of ifconfig which is the ethernet network interface named eno1:

```

# ifconfig

eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.1.2  netmask 255.255.255.0  broadcast 192.168.1.255

        inet6 fe80::3285:a9ff:fe95:1df5  prefixlen 64  scopeid 0x20<link>

        ether 30:85:a9:95:1d:f5  txqueuelen 1000  (Ethernet)

        RX packets 123990  bytes 165595909 (157.9 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 62176  bytes 5374752 (5.1 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

        device interrupt 18  memory 0xf8300000-f8320000  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 1000  (Local Loopback)

        RX packets 4  bytes 290 (290.0 B)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 4  bytes 290 (290.0 B)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

```

Do note that udev is what changes the name from "ethX to eno1", not the kernel.

---------------------------------------------------------------------

Here is my working static-network-service file in /etc/systemd/system/:

```

[Unit]

Description=Static network service

After=local-fs.target

Documentation=man:ifconfig(8)

Documentation=man:route(8)

[Service]

Type=oneshot

RemainAfterExit=yes

ExecStart=/bin/ifconfig eno1 192.168.1.2 broadcast 192.168.1.255 netmask 255.255.255.0 up

ExecStart=/bin/route add default gw 192.168.1.1 eno1

[Install]

WantedBy=multi-user.target

```

---------------------------------------------------------------------

Don't forget to issue this command after all is configured:

```

# systemctl enable static-network.service

```

Then I rebooted into my newly working static IP box running with NetworkManager. NetworkManager re-configured itself automatically to the new static ip settings!

Good luck to all that give this a shot and Thanks to both Mario and elmar283!

----------

