Systemd and static network

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Systemd and static network

Michael Hampicke-7
Howdy folks,

currently I am migrating some servers to systemd, and I am wondering
what's the best way to set up static networking. Until now, I always
used dhcp + networkmanager (workstations, laptops).

Some suggested creating your own network unit and manually start
ifconfig/route or ip via ExecStart, some suggested Arch's netctl which
seems to support static addresses and brings a systemd unit file.

At the moment, following the KISS principle, I tend to a customized unit
file.

What do you use - and what are the benefits of your method?

Have a nice day,
Mike


signature.asc (501 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Systemd and static network

Douglas J Hunley

On Thu, Jul 25, 2013 at 6:46 AM, Michael Hampicke <[hidden email]> wrote:
What do you use - and what are the benefits of your method?

Why not continue to use DHCP and simply set a static assignment based on the MAC inside the DHCP server? Then it doesn't matter how the system is setup, it just works...


--
Douglas J Hunley ([hidden email])
Twitter: @hunleyd                                               Web: douglasjhunley.com
G+: http://goo.gl/sajR3
Reply | Threaded
Open this post in threaded view
|

Re: Systemd and static network

Pavel Volkov

On Thursday 25 July 2013 08:18:00 Douglas J Hunley wrote:


On Thu, Jul 25, 2013 at 6:46 AM, Michael Hampicke <[hidden email]> wrote:

What do you use - and what are the benefits of your method?


Why not continue to use DHCP and simply set a static assignment based on the MAC inside the DHCP server? Then it doesn't matter how the system is setup, it just works...

Systemd will not read /etc/conf.d/net like /etc/init.d/net.* scripts do. You need some service that will prepare the network.

I personally prefer netctl, it is KISS enough. It was me who asked the devs to add it to the tree :)

I tried NM too, it does not work out of the box with systemd, there are several issues.

 

Reply | Threaded
Open this post in threaded view
|

Re: Systemd and static network

Pavel Volkov

On Thursday 25 July 2013 17:23:56 I wrote:

Systemd will not read /etc/conf.d/net like /etc/init.d/net.* scripts do. You need some service that will prepare the network.

I personally prefer netctl, it is KISS enough. It was me who asked the devs to add it to the tree :)

I tried NM too, it does not work out of the box with systemd, there are several issues.

 



Argh, sorry for the distorted quotations.

Reply | Threaded
Open this post in threaded view
|

Re: Systemd and static network

Pavel Volkov

KMail is messing with my emails here, quotations in sent letters are not the way they used to look in edit mode :)

Reply | Threaded
Open this post in threaded view
|

Re: Systemd and static network

Michael Hampicke-7
In reply to this post by Douglas J Hunley
Am 2013-07-25 14:18, schrieb Douglas J Hunley:
> On Thu, Jul 25, 2013 at 6:46 AM, Michael Hampicke <[hidden email]> wrote:
>
>> What do you use - and what are the benefits of your method?
>
> Why not continue to use DHCP and simply set a static assignment based
> on the MAC inside the DHCP server? Then it doesn't matter how the
> system is setup, it just works...
>

There's no DHCP in this particular offsite data center :-)

Reply | Threaded
Open this post in threaded view
|

Re: Systemd and static network

Canek Peláez Valdés
In reply to this post by Michael Hampicke-7
On Thu, Jul 25, 2013 at 5:46 AM, Michael Hampicke <[hidden email]> wrote:

> Howdy folks,
>
> currently I am migrating some servers to systemd, and I am wondering
> what's the best way to set up static networking. Until now, I always
> used dhcp + networkmanager (workstations, laptops).
>
> Some suggested creating your own network unit and manually start
> ifconfig/route or ip via ExecStart, some suggested Arch's netctl which
> seems to support static addresses and brings a systemd unit file.
>
> At the moment, following the KISS principle, I tend to a customized unit
> file.
>
> What do you use - and what are the benefits of your method?

I use the following unit in one of my servers:

# -------------------------------------------------------------------------------------------
[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 <DEVICE> <IP> broadcast <BCAST> netmask <NETMASK> up
ExecStart=/bin/route add default gw <GW> <DEVICE>
# -------------------------------------------------------------------------------------------

Obviously, change the necessary parameters.

The benefit is that it doesn't get any more simple, I believe. If DHCP
is available and I don't want to use NetworkManager, I use the
following unit:

# -------------------------------------------------------------------------------------------
[Unit]
Description=DHCP on %I
After=basic.target

[Service]
ExecStartPre=/bin/ifconfig %I up
ExecStart=/sbin/dhcpcd -B %I

[Install]
WantedBy=multi-user.target
# -------------------------------------------------------------------------------------------

You can then enable the unit with:

systemctl enable [hidden email]

where DEV is enp0s0, or whatever funny name udev gives to your network
card. I think I got the unit from Arch, or maybe I wrote; I honestly
don't remember.

Regards.
--
Canek Peláez Valdés
Posgrado en Ciencia e Ingeniería de la Computación
Universidad Nacional Autónoma de México

Reply | Threaded
Open this post in threaded view
|

Re: Systemd and static network

Canek Peláez Valdés
On Thu, Jul 25, 2013 at 8:50 PM, Jonathan Callen <[hidden email]> wrote:

> On 07/25/2013 11:42 AM, Canek Peláez Valdés wrote:
>> On Thu, Jul 25, 2013 at 5:46 AM, Michael Hampicke <[hidden email]>
>> wrote:
>>> What do you use - and what are the benefits of your method?
>>
>> I use the following unit in one of my servers:
>>
>> # -------------------------------------------------------------------------------------------
>> [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 <DEVICE> <IP> broadcast <BCAST> netmask
> <NETMASK> up
>> ExecStart=/bin/route add default gw <GW> <DEVICE>
>> #
> -------------------------------------------------------------------------------------------
>>
>
> I would recommend replacing those two commands with:
>
> ExecStart=/bin/ip addr add <IP>/<CIDR> dev <DEVICE>
> ExecStart=/bin/ip route add default via <GW> dev <DEVICE>
>
> This uses the newer iproute2 infrastructure, which is supposed to
> replace the deprecated net-tools package (last official release was in
> 2001).
>
> Note also that this uses the CIDR notation for IP addresses.  If you
> were previously using "ifconfig eth0 192.168.1.5 broadcast
> 192.168.1.255 netmask 255.255.255.0", you can simply say "ip addr add
> 192.168.1.5/24 dev eth0" which calculates both netmask and broadcast
> from the "/24" (which means the upper 24 bits are used).

Thanks for the heads up.

Regards.
--
Canek Peláez Valdés
Posgrado en Ciencia e Ingeniería de la Computación
Universidad Nacional Autónoma de México

Reply | Threaded
Open this post in threaded view
|

Re: Systemd and static network

Michael Hampicke-7
In reply to this post by Canek Peláez Valdés
Am 25.07.2013 17:42, schrieb Canek Peláez Valdés:

> On Thu, Jul 25, 2013 at 5:46 AM, Michael Hampicke <[hidden email]> wrote:
>> Howdy folks,
>>
>> currently I am migrating some servers to systemd, and I am wondering
>> what's the best way to set up static networking. Until now, I always
>> used dhcp + networkmanager (workstations, laptops).
>>
>> Some suggested creating your own network unit and manually start
>> ifconfig/route or ip via ExecStart, some suggested Arch's netctl which
>> seems to support static addresses and brings a systemd unit file.
>>
>> At the moment, following the KISS principle, I tend to a customized unit
>> file.
>>
>> What do you use - and what are the benefits of your method?
>
> I use the following unit in one of my servers:
>
> # -------------------------------------------------------------------------------------------
> [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 <DEVICE> <IP> broadcast <BCAST> netmask <NETMASK> up
> ExecStart=/bin/route add default gw <GW> <DEVICE>
> # -------------------------------------------------------------------------------------------
>
> Obviously, change the necessary parameters.
>
> The benefit is that it doesn't get any more simple, I believe. If DHCP
> is available and I don't want to use NetworkManager, I use the
> following unit:
>
> # -------------------------------------------------------------------------------------------
> [Unit]
> Description=DHCP on %I
> After=basic.target
>
> [Service]
> ExecStartPre=/bin/ifconfig %I up
> ExecStart=/sbin/dhcpcd -B %I
>
> [Install]
> WantedBy=multi-user.target
> # -------------------------------------------------------------------------------------------
>
> You can then enable the unit with:
>
> systemctl enable [hidden email]
>
> where DEV is enp0s0, or whatever funny name udev gives to your network
> card. I think I got the unit from Arch, or maybe I wrote; I honestly
> don't remember.
>
> Regards.
>
Tanks. I will give netctl a try in a VM. For now, on real machines, I am
going with the unit you suggested.


signature.asc (501 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Systemd and static network

Keith Dart ♂
Re
CADPrc803kq_c76b1oqp3PksvDgyP5MD+zqLGqcsxk=[hidden email].comCADPrc803kq_c76b1oqp3PksvDgyP5MD+zqLGqcsxk=[hidden email].[hidden email],
Michael Hampicke said:
> Tanks. I will give netctl a try in a VM. For now, on real machines, I
> am going with the unit you suggested.


I'm using netctl on one VM now. I'm... ok with it. for now... it did
seem to break during one update, so I think it's still in flux. And the
configuration is a bit confusing.


-- Keith


--

-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   Keith Dart <[hidden email]>
   public key: ID: 19017044
   <http://www.dartworks.biz/>
   =====================================================================

Reply | Threaded
Open this post in threaded view
|

Re: Systemd and static network

Stefan G. Weichinger-3
In reply to this post by Canek Peláez Valdés
Am 25.07.2013 17:42, schrieb Canek Peláez Valdés:

>> What do you use - and what are the benefits of your method?
>
> I use the following unit in one of my servers:
>
> # -------------------------------------------------------------------------------------------
> [Unit]


My current version, using "ip" :

# cat network.service
[Unit]
Description=Network Connectivity

[Service]
Type=oneshot
RemainAfterExit=yes

EnvironmentFile=/etc/conf.d/network_systemd
ExecStart=/bin/ip link set dev ${interface} up
ExecStart=/bin/ip addr add ${address}/${netmask} broadcast ${broadcast}
dev ${interface}
ExecStart=/bin/ip route add default via ${gateway}

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

[Install]
WantedBy=network.target

----- so that unitfile does not have to be touched again and you only
edit /etc/conf.d/network_systemd ->

# cat /etc/conf.d/network_systemd
PATH=/sbin:/usr/sbin
interface=p4p1
address=192.x.y.z
netmask=255.255.255.0
broadcast=192.x.y.zz
gateway=192.x.y.zzz

-----

I have a second unitfile with a more complicated setup for bridging
(with KVM).

Stefan


Reply | Threaded
Open this post in threaded view
|

Re: Systemd and static network

Michael Hampicke-7
Am 2013-07-26 11:26, schrieb Stefan G. Weichinger:

> Am 25.07.2013 17:42, schrieb Canek Peláez Valdés:
>
>>> What do you use - and what are the benefits of your method?
>>
>> I use the following unit in one of my servers:
>>
>> #
>> -------------------------------------------------------------------------------------------
>> [Unit]
>
>
> My current version, using "ip" :
>
> # cat network.service
> [Unit]
> Description=Network Connectivity
>
> [Service]
> Type=oneshot
> RemainAfterExit=yes
>
> EnvironmentFile=/etc/conf.d/network_systemd
> ExecStart=/bin/ip link set dev ${interface} up
> ExecStart=/bin/ip addr add ${address}/${netmask} broadcast ${broadcast}
> dev ${interface}
> ExecStart=/bin/ip route add default via ${gateway}
>
> ExecStop=/bin/ip addr flush dev ${interface}
> ExecStop=/bin/ip link set dev ${interface} down
>
> [Install]
> WantedBy=network.target
>
> ----- so that unitfile does not have to be touched again and you only
> edit /etc/conf.d/network_systemd ->
>
> # cat /etc/conf.d/network_systemd
> PATH=/sbin:/usr/sbin
> interface=p4p1
> address=192.x.y.z
> netmask=255.255.255.0
> broadcast=192.x.y.zz
> gateway=192.x.y.zzz
>
> -----
>
> I have a second unitfile with a more complicated setup for bridging
> (with KVM).
>
> Stefan

Good idea, I already had forgotten that you could parse variables from
another file in a systemd unit.