You are not logged in.

#1 2018-02-13 13:03:50

sweetthdevil
Member
Registered: 2009-10-20
Posts: 415

Setting up Server to have Static IP

Hello all,

I am setting up a new house network, I have a headless server running Archlinux that is set up with systemd-networkd to connect using the router DHCP. In the past, I have always assigned a static IP directly on the router.

This time, I must set up the server static IP from the systemd-networkd directly. However, I want to make sure that I am going to get it right as if not I am losing access to the headless  server as I am unable to connect keyboard/mouse and/or display and would need to reinstall.

So, if I understand the following example copied from the wiki (https://wiki.archlinux.org/index.php/sy … _static_IP)
The name is the name of the connection on the server in this case eth0.The "address" is the desired static ip address, "gateway" and "dns" are the router's address, the "/24" following the address is the part that I am struggling.

[Match]
Name=enp1s0

[Network]
Address=10.1.10.9/24
Gateway=10.1.10.1
DNS=10.1.10.1
#DNS=8.8.8.8

So that would be the configuration file if the router address is 192.168.0.1. and that I want the server address to be 192.168.1.99

[Match]
Name=eth0

[Network]
Address=192.168.1.99/24
Gateway=192.168.0.1
DNS=192.168.0.1
#DNS=8.8.8.8

Also, is there a way to test the connection from SSH that would confirm it worked prior to changing it for good? I.E. that systemd-networkd stop the DHCP connection and test the new configuration then come back to the DHCP if failed?

Thank you for your time, and I am looking forward to your replies

Offline

#2 2018-02-13 13:17:06

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,427

Re: Setting up Server to have Static IP

Trying to hide the fact you are using Arch ARM while keeping most of the other parts of the post the same really isn't smart.

Last warning: If your server uses Arch ARM, ask the question on the Arch ARM boards.

Closing. -- For deletion

Had a correspondence over email, and it should in fact be a separate system running Arch Linux, reopened on appeal.

Last edited by V1del (2018-02-13 13:47:39)

Offline

#3 2018-02-13 18:36:00

lo1
Member
Registered: 2017-09-25
Posts: 584

Re: Setting up Server to have Static IP

sweetthdevil wrote:

the "/24" following the address is the part that I am struggling

An ip address is, shortly, a 2^32 number expressed in bits in binary code, and combines a prefix with a "host number" (I don't know how to call it better). 192.168.1.99/24 means that your prefix locks 2^24  bits (the first three dotted fields) and leaves 2^8 bits free (which is equal to 256 bits free, from 0 to 255).

In this example two addresses are used and mandatory for the network definition, these are 192.168.1.0 (network address) and 192.168.1.255 (broadcast address). So any ip address which stays within this portion of network belongs to the same "subnet".

What you want is, first of all, either correct the gateway address so that it belongs to the 192.168.1.x/24 subnet or correct the server ip to 192.168.0.99.

lso, is there a way to test the connection from SSH that would confirm it worked prior to changing it for good? I.E. that systemd-networkd stop the DHCP connection and test the new configuration then come back to the DHCP if failed?

I'm not sure what you're asking, surely there's a way to test it from ssh, and that would be make sure you configured and started an ssh daemon along with setting your firewall to allow ssh connections. https://wiki.archlinux.org/index.php/Secure_Shell

The DHCP part has nothing to do with this, and if you want to assign a static ip address to your server you have to forget about it.

Offline

#4 2018-02-13 19:13:45

sweetthdevil
Member
Registered: 2009-10-20
Posts: 415

Re: Setting up Server to have Static IP

Ok thanks for the information and for explaining the CIRD, I have been reading on it and I am miles away from getting it.

Anyway, the server was previously used (in another house) at 192.168.1.99 - the router providing by the ISP only allow DHCP from 192.168.1.1 to 99. I am assuming (due to research on the new router provided by the new ISP) that the range for the DHCP is 192.168.0.1 to .99.

It would be easier if the IP for the server did not change as it is mainly used to host media files shared amongst several Kodi with a shared database. Changing the address will means that the database will have to be started from 0.

Regarding testing the systemd-networkd, I connect to that headless server via SHH (either from my laptop or my phone) as I cannot connect a keyboard/mouse and or a display - if that new connection setting failed and the server remains offline I am then stuck and in need to re-install the server (which I am now looking forward to)

Therefore, if there was a way to test that new static ip setup for either a set amount of minutes or that if it failed to connect that it will reconnect using the DHCP setup.

I hope this clears it.

Thanks,

Offline

#5 2018-02-14 18:07:51

lo1
Member
Registered: 2017-09-25
Posts: 584

Re: Setting up Server to have Static IP

if that new connection setting failed and the server remains offline I am then stuck and in need to re-install the server

There's hundreds of ways to check if a specific network setup would cut you off, the first I can think of is booting into the arch-iso and setting the connection using the ip-utils packages (ip address, ip route...). So if you fail to do something you can just reboot your server.

It would be easier if the IP for the server did not change as it is mainly used to host media files shared amongst several Kodi with a shared database. Changing the address will means that the database will have to be started from 0.

I've no idea of how Kodi works, but this seems just pathetic. If this is really how it works, I suggest you switch to a more reliable option.

Therefore, if there was a way to test that new static ip setup for either a set amount of minutes or that if it failed to connect that it will reconnect using the DHCP setup.

https://wiki.archlinux.org/index.php/Cron
https://wiki.archlinux.org/index.php/Systemd/Timers

Create and enable two units, one that disables dhcp and sets static addressing and one that does the opposite, schedule them so that you have enough time to check for errors and try your network.

Offline

#6 2018-02-15 20:46:22

sweetthdevil
Member
Registered: 2009-10-20
Posts: 415

Re: Setting up Server to have Static IP

Thank you so much for your reply! Never thought of cron!! Thinking of it now could easily write a bash script that does the trick as well....

Regarding Kodi, it's not so much Kodi itself at fault there, I have setup a central MySql database in order for my file to be available throughout the network for all Kodi boxes but more importantly that the files are marked as watched everywhere! So, in essence, it's the MySql database that contains the route to the file that demands the server on the same IP address.

There is a way to update the route in MySql but frankly, after reading the Kodi wiki to achieve that I got a migraine and did not even wanted to try.

One last question if I may. If the router is located on 192.168.0.1, my understanding of your previous reply is that I cannot have the server on 192.168.1.99.

For me the idea of changing the setting of the server systemd-networkd to that specific ip was that doesn't matter if the network (i.e. router) change it will always remain at that address (very unlikely to be already used).

Again, thank you!

Offline

#7 2018-02-15 21:12:13

lo1
Member
Registered: 2017-09-25
Posts: 584

Re: Setting up Server to have Static IP

So, in essence, it's the MySql database that contains the route to the file that demands the server on the same IP address.
.....
For me the idea of changing the setting of the server systemd-networkd to that specific ip was that doesn't matter if the network (i.e. router) change it will always remain at that address (very unlikely to be already used).

Now I'm having migraine too, I think I'm going to read on my own how does MySQL work.

One last question if I may. If the router is located on 192.168.0.1, my understanding of your previous reply is that I cannot have the server on 192.168.1.99.

You *could*, if this router can assign different addresses to different interfaces in different LANs. That is, if your router allows multiple "broadcast domains", and it allows to assign specific addresses to each interface, you would have e.g.:

router eth1 interface 192.168.0.1 connected to PC interface 192.168.0.2
router eth2 interface 192.168.1.1 connected to server 192.168.1.99

with "router" being the gateway from 192.168.0.0/24 to 192.168.1.0/24.

I seriously doubt most home routers are capable of doing this, so this is just FYI.

Offline

#8 2018-02-15 21:17:29

sweetthdevil
Member
Registered: 2009-10-20
Posts: 415

Re: Setting up Server to have Static IP

Right,

Well I am getting the router next Monday, I have the feeling that won't work. Anyway, will give it a go.

You have been a star! Thanks

Offline

Board footer

Powered by FluxBB