View previous topic :: View next topic |
Author |
Message |
pmam Veteran
Joined: 30 Dec 2013 Posts: 1145
|
Posted: Wed Apr 02, 2014 8:06 am Post subject: how static IP in systemd |
|
|
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 |
|
|
Marlo Veteran
Joined: 26 Jul 2003 Posts: 1591
|
Posted: Wed Apr 02, 2014 10:10 am Post subject: |
|
|
try this:
/etc/systemd/system/static-network.service wrote: |
[Unit]
Description=Static network service
After=local-fs.target
Documentation=man:ifconfig(
Documentation=man:route(
[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 |
|
|
pmam Veteran
Joined: 30 Dec 2013 Posts: 1145
|
Posted: Wed Apr 02, 2014 12:39 pm Post subject: |
|
|
Marlo Hi,
As I noted in my post I am new in gentoo...
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 |
|
|
elmar283 Guru
Joined: 06 Dec 2004 Posts: 316 Location: Haarlem, Netherlands
|
Posted: Sun Jul 20, 2014 1:57 pm Post subject: |
|
|
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:
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 |
|
|
comprookie2000 Retired Dev
Joined: 25 Jul 2004 Posts: 925 Location: Sun City Center, Florida
|
Posted: Mon Jul 21, 2014 12:22 am Post subject: |
|
|
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 |
|
|
pmam Veteran
Joined: 30 Dec 2013 Posts: 1145
|
Posted: Mon Jul 21, 2014 7:27 am Post subject: |
|
|
Dear elmar283 & comprookie2000,
Quote: | Might be a little late but better late then never. |
Yes, a little bit late 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 |
|
|
elmar283 Guru
Joined: 06 Dec 2004 Posts: 316 Location: Haarlem, Netherlands
|
|
Back to top |
|
|
gcyoung Apprentice
Joined: 04 Jul 2007 Posts: 170 Location: England
|
Posted: Tue May 09, 2017 4:53 pm Post subject: Unit Static-network.service |
|
|
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 |
|
|
axl Veteran
Joined: 11 Oct 2002 Posts: 1144 Location: Romania
|
Posted: Tue May 09, 2017 7:03 pm Post subject: |
|
|
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 |
|
|
gcyoung Apprentice
Joined: 04 Jul 2007 Posts: 170 Location: England
|
Posted: Wed May 10, 2017 3:56 pm Post subject: Static-network.service |
|
|
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 |
|
|
Zucca Moderator
Joined: 14 Jun 2007 Posts: 3343 Location: Rasi, Finland
|
Posted: Wed May 10, 2017 4:18 pm Post subject: |
|
|
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 |
|
|
gcyoung Apprentice
Joined: 04 Jul 2007 Posts: 170 Location: England
|
Posted: Sat May 13, 2017 12:24 pm Post subject: static-network settings |
|
|
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 |
|
|
Xootneg n00b
Joined: 19 Oct 2003 Posts: 23 Location: N. California
|
Posted: Fri Feb 02, 2018 6:09 pm Post subject: |
|
|
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. 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 |
|
|
|