Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
how static IP in systemd
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
pmam
Veteran
Veteran


Joined: 30 Dec 2013
Posts: 1145

PostPosted: Wed Apr 02, 2014 8:06 am    Post subject: how static IP in systemd Reply with quote

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.
Back to top
View user's profile Send private message
Marlo
Veteran
Veteran


Joined: 26 Jul 2003
Posts: 1591

PostPosted: Wed Apr 02, 2014 10:10 am    Post subject: Reply with quote

try this:
/etc/systemd/system/static-network.service wrote:

[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 enp5s0 192.168.1.2 broadcast 192.255.255.255 netmask 255.0.0.0 up
ExecStart=/bin/route add default gw 192.168.1.1 enp5s0

[Install]
WantedBy=multi-user.target


enp5s0 is my network cart. <use your own networknumbers>
_________________
------------------------------------------------------------------
http://radio.garden/
Back to top
View user's profile Send private message
pmam
Veteran
Veteran


Joined: 30 Dec 2013
Posts: 1145

PostPosted: Wed Apr 02, 2014 12:39 pm    Post subject: Reply with quote

Marlo Hi,

As I noted in my post I am new in gentoo... :D
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
Back to top
View user's profile Send private message
elmar283
Guru
Guru


Joined: 06 Dec 2004
Posts: 316
Location: Haarlem, Netherlands

PostPosted: Sun Jul 20, 2014 1:57 pm    Post subject: Reply with quote

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:
Code:

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:
Code:

chmod +x static-network.service
systemctl enable static-network.service
systemctl start static-network.service


And finaly to check if it works:
Code:

ifconfig


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

Hope this answers your question.
Back to top
View user's profile Send private message
comprookie2000
Retired Dev
Retired Dev


Joined: 25 Jul 2004
Posts: 925
Location: Sun City Center, Florida

PostPosted: Mon Jul 21, 2014 12:22 am    Post subject: Reply with quote

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
_________________
http://dev.gentoo.org/~dabbott/
Back to top
View user's profile Send private message
pmam
Veteran
Veteran


Joined: 30 Dec 2013
Posts: 1145

PostPosted: Mon Jul 21, 2014 7:27 am    Post subject: Reply with quote

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
_________________
“You can take our property, our sweet homes, even our cloths...
But don't touch the streets, Ah, That's NO, NO, NO!
The streets are our @world's compilable kernel ...”
Back to top
View user's profile Send private message
elmar283
Guru
Guru


Joined: 06 Dec 2004
Posts: 316
Location: Haarlem, Netherlands

PostPosted: Mon Jul 21, 2014 12:26 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
gcyoung
Apprentice
Apprentice


Joined: 04 Jul 2007
Posts: 170
Location: England

PostPosted: Tue May 09, 2017 4:53 pm    Post subject: Unit Static-network.service Reply with quote

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
Back to top
View user's profile Send private message
axl
Veteran
Veteran


Joined: 11 Oct 2002
Posts: 1144
Location: Romania

PostPosted: Tue May 09, 2017 7:03 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
gcyoung
Apprentice
Apprentice


Joined: 04 Jul 2007
Posts: 170
Location: England

PostPosted: Wed May 10, 2017 3:56 pm    Post subject: Static-network.service Reply with quote

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!
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3339
Location: Rasi, Finland

PostPosted: Wed May 10, 2017 4:18 pm    Post subject: Reply with quote

I use systemd-networkd on my systemd PC.
The documentation on the wiki is poor a the moment.
This is what I have:
/etc/systemd/network/55-ib.network:
[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:
/etc/systemd/network/50-dhcp.network:
[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.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
gcyoung
Apprentice
Apprentice


Joined: 04 Jul 2007
Posts: 170
Location: England

PostPosted: Sat May 13, 2017 12:24 pm    Post subject: static-network settings Reply with quote

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.
Back to top
View user's profile Send private message
Xootneg
n00b
n00b


Joined: 19 Oct 2003
Posts: 23
Location: N. California

PostPosted: Fri Feb 02, 2018 6:09 pm    Post subject: Reply with quote

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:

Code:
# 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. :) Then I rebooted and the network was dead. :cry: 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:

Code:
# 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:

Code:

# 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/:

Code:

[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:

Code:

# 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!
_________________
Confucius Says: "Even monkeys fall out of trees"!

http://www.eldoradocountyweather.com
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum