You are not logged in.

#1 2013-02-12 19:01:24

miky76
Member
From: Italy
Registered: 2011-10-27
Posts: 135

Systemd, how to set static IP

Hi,
my internet provider give me 3 IP addresses, the first pc that start get the first, and so on

when I was using rc.conf it was easy to set a static ip to one of the pc active on my network

now I have systemd and the network works fine, but I do not know how to set a fix ip to it.

i'm browing around and i found out that i have to modify few files, that i did, but it still taking the worng IP when it reboot:

/etc/conf.d/network

interface=eth0
address=10.40.50.95
netmask=255.255.248.0
broadcast=10.40.55.255
gateway=10.40.48.1

/etc/systemd/system/network.service

[Unit]
 Description=Static IP Connectivity
 Wants=network.target
 Before=network.target

 [Service]
 Type=oneshot
 RemainAfterExit=yes
 EnvironmentFile=/etc/conf.d/network
 ExecStart=/sbin/ip link set dev ${interface} up
 #ExecStart=/usr/sbin/wpa_supplicant -B -i ${interface} -c /etc/wpa_supplicant.conf # Remove this for wired connections
 ExecStart=/sbin/ip addr add ${address}/${netmask} broadcast ${broadcast} dev ${interface}
 ExecStart=/sbin/ip route add default via ${gateway}

 ExecStop=/sbin/ip addr flush dev ${interface}
 ExecStop=/sbin/ip link set dev ${interface} down

 [Install]
 WantedBy=multi-user.target

also

systemctl report:

......
lvmetad.service             loaded active running   LVM2 metadata daemon
network.service             loaded active exited    Static IP Connectivity
NetworkManager.service      loaded active running   Network Manager
nmbd.service                loaded active running   Samba NetBIOS name server
......

i'm not sure why I have the network.service that in exited status sad

can you help me to fix the IP? what is missing?

Offline

#2 2013-02-12 22:36:01

ron9
Member
From: Norway
Registered: 2011-02-02
Posts: 103

Re: Systemd, how to set static IP

It is unit type oneshot so it has done its job and have exited. It is as it should be.
You have set RemainAfterExit so it will remain and not stopping unless user responds.
I see you have networkmanager running. What do you use it for? Dos it use static ip?
I have the same setup myself and it works as it should. Systemd 197 rename interfaces so
look at your ip l (shortform for ip link) to find your interface and ip a to see if ip address is assigned to interface.

edit: correct typo

Last edited by ron9 (2013-02-12 22:51:29)


archlinux x86_64 | openbox | urxvt | zsh | xfe | qupzilla

Offline

#3 2013-02-13 00:57:36

hawaiicharles
Member
Registered: 2012-12-21
Posts: 71

Re: Systemd, how to set static IP

I've been told that it's better to use netcfg.  For a static address, copy /etc/network.d/examples/ethernet-static into /etc/network.d/ (and rename it if you want), and then change the parameters in there.  The example file is missing a NETMASK line, so add the line
NETMASK=24
(or whatever your netmask is).  Lastly, enable the network by typing
systemctl enable netcfg@ethernet-static
The netcfg wiki explains everything.

The reason that netcfg is better is because it plays nice with other system services, such as network file mounts (NFS or CIFS), while the method above does not.

P.S.  As ron9 said above, your ethernet adapter name probably won't be "eth0".  Type "ip link" to find out what it is, and then modify your ethernet-static file accordingly.

Last edited by hawaiicharles (2013-02-13 00:59:50)

Offline

#4 2013-02-13 12:50:53

revellion
Member
From: Sweden
Registered: 2007-04-10
Posts: 51

Re: Systemd, how to set static IP

I can also recommend using Netcfg instead, makes it easier to create multiple profiles aswell if you've got more advanced setups with VLANs etc.

hawaiicharles wrote:

I've been told that it's better to use netcfg.  For a static address, copy /etc/network.d/examples/ethernet-static into /etc/network.d/ (and rename it if you want), and then change the parameters in there.  The example file is missing a NETMASK line, so add the line
NETMASK=24
(or whatever your netmask is).  Lastly, enable the network by typing
systemctl enable netcfg@ethernet-static
The netcfg wiki explains everything.

The reason that netcfg is better is because it plays nice with other system services, such as network file mounts (NFS or CIFS), while the method above does not.

P.S.  As ron9 said above, your ethernet adapter name probably won't be "eth0".  Type "ip link" to find out what it is, and then modify your ethernet-static file accordingly.


Hurricane Electric Certified IPv6 Sage

CPU: Core i7-2600 @ 4.0Ghz | RAM: 16GB (4x4GB) | GFX: AMD Radeon R9 290 4096MB VRAM | HDD: 1x 120GB SATA3 Corsair SSD (~500MB/s RW), 1x SATA2 250GB, 1x SATA2 320GB, 1x 180GB SATA3 Intel SSD
*EDIT* Replaced Nvidia GTX 570 for a AMD Radeon R9 290, and added an extra SSD 180GB

Offline

#5 2013-02-13 21:42:55

miky76
Member
From: Italy
Registered: 2011-10-27
Posts: 135

Re: Systemd, how to set static IP

Hi thanks for your answers

why do I use NetworkManager? I do not know, when I moved to systemd, it had a name that attracted me smile (it's not a good answer I know tongue)

the results of the 2 commands you asked me

[root@artemide ~]# ip l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
    link/ether 14:da:e9:93:d8:59 brd ff:ff:ff:ff:ff:ff
[root@artemide ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 14:da:e9:93:d8:59 brd ff:ff:ff:ff:ff:ff
    inet 10.40.50.94/21 brd 10.40.55.255 scope global eth0
    inet6 fe80::16da:e9ff:fe93:d859/64 scope link
       valid_lft forever preferred_lft forever

the address 10.40.50.94 is the one that it get dinamically at boot and that I want to make it static with 10.40.50.95



here is my old rc.conf file

interface="eth0"
address=10.40.50.95
netmask=255.255.248.0
broadcast=
gateway=10.40.48.1

for me it's ok to install and use netcfg, but what can I do for make sure it will be the one it's on and how can I uninstall the network.manager one?

thanks

Last edited by miky76 (2013-02-13 21:48:18)

Offline

#6 2013-02-13 21:48:35

progandy
Member
Registered: 2012-05-17
Posts: 2,143

Re: Systemd, how to set static IP

for me it's ok to install and use netcfg, but what can I do for make sure it will be the one it's on and how can I uninstall the network.manager one?

If you don't want networkmanager, uninstall it (pacman -R networkmanager)
Then make sure no dhcp service is enabled (neither dhcpcd.service nor dhcpcd@eth0.service)
Install netcfg (If you use the testing repo I'd recommend netctl), create your profiles and enable them.

Offline

#7 2013-02-13 23:28:42

nomorewindows
Member
Registered: 2010-04-03
Posts: 2,947

Re: Systemd, how to set static IP

You have to then after configuring your netcfg profiles enable it with systemd: systemctl enable netcfg@<interface>.


I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.

Offline

#8 2013-02-21 00:23:50

miky76
Member
From: Italy
Registered: 2011-10-27
Posts: 135

Re: Systemd, how to set static IP

I've installed netcfg but when I try to associate the profile it tells me network unreachable

what i did:

I've copied the file "ethernet-static" from the example folder, and I've put it in /etc/network.d

I've modified it in this way:

CONNECTION='ethernet'
DESCRIPTION='A basic static ethernet connection using iproute'
INTERFACE='eth0'
IP='static'
ADDR='10.40.50.95'
#ROUTES=('192.168.0.0/24 via 192.168.1.2')
GATEWAY='10.40.48.1'
DNS=('8.8.8.8') #google dns  

than i type:

systemctl stop dhcpcd@eth0.service

netcfg mynetwork_file

result

:: mynetwork_file up
RTNETLINK answers: Network is unreachable
 > Adding gateway 10.40.48.1 failed 

can you help me with this?

thanks

Last edited by miky76 (2013-02-21 21:01:11)

Offline

#9 2013-02-21 00:55:13

the sad clown
Member
From: 192.168.0.X
Registered: 2011-03-20
Posts: 833

Re: Systemd, how to set static IP

You might want to also consider netctl, as it is slated to be netcfg's replacement with better systemd integration.


I laugh, yet the joke is on me

Offline

#10 2013-02-21 01:29:06

nomorewindows
Member
Registered: 2010-04-03
Posts: 2,947

Re: Systemd, how to set static IP

miky76 wrote:

I've installed netcfg but when I try to associate the profile it tells me network unreachable

what i did:

I've copied the file "ethernet-static" from the example folder, and I've put it in /etc/network.d

I've modified it in this way:

CONNECTION='ethernet'
DESCRIPTION='A basic static ethernet connection using iproute'
INTERFACE='eth0'
IP='static'
ADDR='10.40.50.95'
#ROUTES=('192.168.0.0/24 via 192.168.1.2')
GATEWAY='10.40.48.1'
DNS=('8.8.8.8')   

than i type:#google dns

systemctl stop dhcpcd@eth0.service

netcfg mynetwork_file

result

:: mynetwork_file up
RTNETLINK answers: Network is unreachable
 > Adding gateway 10.40.48.1 failed 

can you help me with this?

thanks

Your netmask would have to be 255.255.0.0, (oops, you have 255.255.248.0), you may have to explicitly set this in the config file.
and with systemctl you would just start it with systemctl start/enable netcfg@mynetwork_file when you're sure everything is working.

Last edited by nomorewindows (2013-02-21 01:29:53)


I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.

Offline

#11 2013-02-21 02:00:27

hawaiicharles
Member
Registered: 2012-12-21
Posts: 71

Re: Systemd, how to set static IP

miky76 wrote:

I've installed netcfg but when I try to associate the profile it tells me network unreachable

what i did:

I've copied the file "ethernet-static" from the example folder, and I've put it in /etc/network.d

I've modified it in this way:

CONNECTION='ethernet'
DESCRIPTION='A basic static ethernet connection using iproute'
INTERFACE='eth0'
IP='static'
ADDR='10.40.50.95'
#ROUTES=('192.168.0.0/24 via 192.168.1.2')
GATEWAY='10.40.48.1'
DNS=('8.8.8.8')   

than i type:#google dns

systemctl stop dhcpcd@eth0.service

netcfg mynetwork_file

result

:: mynetwork_file up
RTNETLINK answers: Network is unreachable
 > Adding gateway 10.40.48.1 failed 

can you help me with this?

thanks

I don't know why, but the example file is missing a NETMASK entry.  You have to add it manually, and you can use either of 2 formats:
NETMASK=255.255.248.0
- or -
NETMASK=21

It seems to work OK without a NETMASK entry if you're on a 24-bit subnet, but for anything else, you need the entry.

Offline

#12 2013-02-21 03:37:26

hunterthomson
Member
Registered: 2008-06-22
Posts: 794
Website

Re: Systemd, how to set static IP

Well, I am sure it works fine without the NETMASK as long as it a Classful IP subnet, not just /24.

Class A: 1.0.0.0-126.255.255.255/8
Class B: 128.0.0.0-191.255.255.255/16
Class C: 192.0.0.0-223.255.255.255/24

Last edited by hunterthomson (2013-02-21 03:46:11)


OpenBSD-current Thinkpad X230, i7-3520M, 16GB CL9 Kingston, Samsung 830 256GB
Contributor: linux-grsec

Offline

#13 2013-02-21 21:46:09

miky76
Member
From: Italy
Registered: 2011-10-27
Posts: 135

Re: Systemd, how to set static IP

Thanks to All,
i've added the netmask to the mynetwork_file and doing this

systemctl stop dhcpcd@eth0.service

netcfg mynetwork_file

the result is network up [DONE]

I've added in /etc/conf.d/netcfg the line

NETWORKS=(mynetwork_file)

and started the dhcp

systemctl stop dhcpcd@eth0.service
systemctl disable NetworkManager

during reboot the network configuration fail, bcos it's still looking for NetworkManager and netcfg fail too

running systemctl the result is:

.........
dhcpcd@eth0.service         loaded failed failed   dhcpcd on eth0
........
netcfg.service              loaded failed failed    Netcfg multi-profile daemon
network.service             loaded active exited    Static IP Connectivity
.......

I enabled again NetworkManager for use the network...

Offline

#14 2013-02-21 21:51:51

miky76
Member
From: Italy
Registered: 2011-10-27
Posts: 135

Re: Systemd, how to set static IP

this maybe can be useful

[root@artemide ~]# systemctl status netcfg
netcfg.service - Netcfg multi-profile daemon
          Loaded: loaded (/usr/lib/systemd/system/netcfg.service; enabled)
          Active: failed (Result: exit-code) since Thu 2013-02-21 22:47:22 CET; 3min 9s ago
        Main PID: 282 (code=exited, status=1/FAILURE)
          CGroup: name=systemd:/system/netcfg.service

Feb 21 22:47:18 artemide systemd[1]: Starting Netcfg multi-profile daemon...
Feb 21 22:47:22 artemide netcfg-daemon[282]: :: mik_network up RTNETLINK answers: File exists
Feb 21 22:47:22 artemide netcfg-daemon[282]: Could not configure interface
Feb 21 22:47:22 artemide netcfg-daemon[282]: [fail]
Feb 21 22:47:22 artemide systemd[1]: netcfg.service: main process exited, code=exited, status=1/FAILURE
Feb 21 22:47:22 artemide systemd[1]: Failed to start Netcfg multi-profile daemon.
Feb 21 22:47:22 artemide systemd[1]: Unit netcfg.service entered failed state
[root@artemide ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 14:da:e9:93:d8:59 brd ff:ff:ff:ff:ff:ff
    inet 10.40.50.94/21 brd 10.40.55.255 scope global eth0
    inet6 fe80::16da:e9ff:fe93:d859/64 scope link
       valid_lft forever preferred_lft forever

Last edited by miky76 (2013-02-21 21:54:01)

Offline

Board footer

Powered by FluxBB