Setting Up A Static IP Address

Kernel, Main, Utilities & Applications, Miscellaneous Devices.
jca
Top Contributor
Posts: 1911
Joined: Wed May 27, 2020 1:59 pm
Has thanked: 145 times
Been thanked: 454 times

Setting Up A Static IP Address

Unread post by jca »

I am trying to setup my MISTer with a static address.
For reasons too long to discuss I am not in a position to use the MAC address and setup the IP in the router.
So far I used:
ifconfig eth0 192.168.80.38 netmask 255.255.255.0
route add default gw 192.168.80.254
echo "nameserver 8.8.8.8" > /etc/resolv.conf

It works .. until I reboot because the DHCP server is still running.
I could not find dhcpconfig or the DHCP manager to disable the dhcp service.
In edited the file /etc/network/interfaces and replaced each occurrence of dhcp with static but it did not work.
I suspect I am on the right track but the order to do it may be the problem.

Any help would be highly appreciated.
User avatar
pgimeno
Top Contributor
Posts: 710
Joined: Thu Jun 11, 2020 9:44 am
Has thanked: 277 times
Been thanked: 226 times

Re: Setting Up A Static IP Address

Unread post by pgimeno »

jca
Top Contributor
Posts: 1911
Joined: Wed May 27, 2020 1:59 pm
Has thanked: 145 times
Been thanked: 454 times

Re: Setting Up A Static IP Address

Unread post by jca »

pgimeno wrote: Mon Nov 30, 2020 12:36 am Maybe this helps?

https://wiki.debian.org/NetworkConfigur ... e_manually
Thanks for the link. It did not really help but I followed some links which lead me to other links (almost ad infinitum).
I tried quite a few things like totally scraping the /etc/network/interfaces file and replacing it with
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.80.38
netmask 255.255.255.0
gateway 192.168.80.254
dns-nameservers 8.8.8.8

When booting MISTer and going really fast to the screen which displays the IP I could see that I was getting the right IP but a few seconds it displayed the old DHCP address. At that point MISTer had 2 IP addresses and I could ssh or ftp using either one.

I edited the dhcpcd.conf file to prevent dhcp assigning a dhcp address to eth0 with
denyinterfaces eth0

No change

I renamed the dhcpcd client to something else: no change.

I restored the interfaces files to its original status and edited again the dhcpcd.conf file:
I removed the denyinterfaces and added

interface eth0
static ip_address=192.168.80.38/24
static routers=192.168.80.254
static domain_name_servers=192.168.80.3 8.8.8.8

Same darn thing, I am going insane.

Help, help, help.
shira
Posts: 20
Joined: Sat May 30, 2020 10:54 am
Has thanked: 21 times
Been thanked: 11 times

Re: Setting Up A Static IP Address

Unread post by shira »

zakk4223
Posts: 289
Joined: Sun May 24, 2020 10:55 pm
Been thanked: 120 times

Re: Setting Up A Static IP Address

Unread post by zakk4223 »

It's because mister uses 'connmand' to configure the interface, and I guess it isn't smart enough to not dhcp if it already has an address?

Anyways, setup your /etc/network/interfaces with the static config, and then create the file /etc/connman/main.conf (if the directory isn't there create it) and put these two lines in it:
[General]
NetworkInterfaceBlacklist=eth0

There is also a way to use connmanctl to set a static ip address that will save in /var/lib/connman (you have to create that directory) but that seems overly complicated compared to the interfaces file
jca
Top Contributor
Posts: 1911
Joined: Wed May 27, 2020 1:59 pm
Has thanked: 145 times
Been thanked: 454 times

Re: Setting Up A Static IP Address

Unread post by jca »

Thanks for the info, I will try it later when I am back home.
Shall I trash all the stuff related to wlan0 and wlan1 from the interfaces file? I do not use WiFi.

Something like that:

# interface file auto-generated by buildroot

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.80.38
netmask 255.255.255.0
gateway 192.168.80.254
dns-nameservers 8.8.8.8
zakk4223
Posts: 289
Joined: Sun May 24, 2020 10:55 pm
Been thanked: 120 times

Re: Setting Up A Static IP Address

Unread post by zakk4223 »

There's no harm in leaving the wlan0/1 stuff there; just add your eth0 config to the end
jca
Top Contributor
Posts: 1911
Joined: Wed May 27, 2020 1:59 pm
Has thanked: 145 times
Been thanked: 454 times

Re: Setting Up A Static IP Address

Unread post by jca »

Thanks for the help, I am ALMOST there.
At the moment I just replaced the interface file with what I mentioned in my previous post, ditching the wlan stuff.
I created the directory and file /etc/connman/main.conf.
Now I can start MISTer and get the fixed IP. No extra IP like before. I can ftp and ssh.
Only problem left: no internet.
Thinking of a routing problem I issued
route add default gw 192.168.80.254, still nothing.

route -en gives
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.80.254 0.0.0.0 UG 0 0 0 eth0
0.0.0.0 192.168.80.254 0.0.0.0 UG 0 0 0 eth0
192.168.80.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

I can ping the gateway, I have internet on my PC.
jca
Top Contributor
Posts: 1911
Joined: Wed May 27, 2020 1:59 pm
Has thanked: 145 times
Been thanked: 454 times

Re: Setting Up A Static IP Address

Unread post by jca »

Problem solved:
Although I have
dns-nameservers 8.8.8.8
in the interface file the contents of /etc/resolv.conf was just the loopback address.
echo "nameserver 8.8.8.8" >/etc/resolv.conf resolved (no pun intended) the problem.

I just checked the man page for interface and dns-nameservers does not appear.
On my first attempts to setup a fixed IP I was using the echo method. On my last failed attempt I found this dns-nameservers thing on the internet and thought is was cool. No so cool in the end.

Many thanks to zakk4223.
jca
Top Contributor
Posts: 1911
Joined: Wed May 27, 2020 1:59 pm
Has thanked: 145 times
Been thanked: 454 times

Re: Setting Up A Static IP Address

Unread post by jca »

My problem is only partially solved:
The setting in /etc/resolv.conf is not permanent. After a reboot it reverts to:
# Generated by Connection Manager
nameserver 127.0.0.1
connman is recreating the file. I do not know anything about connman; I tried looking on the internet but so far without any result.
I could write a script to overwrite resolv.conf and run it after booting but it would be a band-aid.
Does anyone knows how to fix it?
Johnny Love
Posts: 12
Joined: Sun Aug 16, 2020 3:51 pm

Re: Setting Up A Static IP Address

Unread post by Johnny Love »

You can make any script run at boot by putting it in/etc/init.d, but I would start the filename with 9999 to make sure it runs last. Obviously not the ideal fix, but it beats running a script manually every time. Also expect the script to get wiped after linux gets updated, which is not that often. A backup of it in /media/fat should be fine.
jca
Top Contributor
Posts: 1911
Joined: Wed May 27, 2020 1:59 pm
Has thanked: 145 times
Been thanked: 454 times

Re: Setting Up A Static IP Address

Unread post by jca »

Thanks for this idea.
I will also put my script which keeps my USB HDD spinning. I will try it when I am back home.
jca
Top Contributor
Posts: 1911
Joined: Wed May 27, 2020 1:59 pm
Has thanked: 145 times
Been thanked: 454 times

Re: Setting Up A Static IP Address

Unread post by jca »

Johnny Love wrote: Thu Dec 10, 2020 7:28 pm You can make any script run at boot by putting it in/etc/init.d, but I would start the filename with 9999 to make sure it runs last. Obviously not the ideal fix, but it beats running a script manually every time. Also expect the script to get wiped after linux gets updated, which is not that often. A backup of it in /media/fat should be fine.
After another major power failure of 8 hours I finally wrote 2 scripts which I put in init.d:
S99dns for internet access and S99spin to have my USB drive spinning forever, now I don't have to manually execute scripts after booting MISTer.
Many thanks Johnny, I Love you :lol:
Zarkov
Posts: 32
Joined: Wed Sep 22, 2021 7:42 am
Been thanked: 2 times

Re: Setting Up A Static IP Address

Unread post by Zarkov »

Hi there, I'm also trying to setup static ip on my mister and found this thread.

I was only successful getting my mister online and updating by using the pre patch "connmanctl" command. Once the mister was updated, this command is now gone.

I followed your info and got my ip, netmask, gateway, and that dns-nameservers setup in my interfaces file
I can not get the dns to work in the resolv.conf file. It says its managed by dhcpcd.

Thanks for your time.
Flandango
Core Developer
Posts: 459
Joined: Wed May 26, 2021 9:35 pm
Has thanked: 59 times
Been thanked: 383 times

Re: Setting Up A Static IP Address

Unread post by Flandango »

Network configuration is now done with dhcpcd. You will have to modify the /etc/dhcpcd.conf file to setup a static ip.
Add something like this on the bottom of the file:

Code: Select all

interface eth0
static ip_address=192.168.0.XX/24
static routers=192.168.0.X
static domain_name_servers=192.168.0.X 8.8.8.8
For DNS, you don't need to Provide more than one but if you do, just leave a space between them.
The Static IP address has the /24 for the netmask, if you don't know what your network has, then leave it as /24 as that's the most common for home networks.

As a side note, copy this file to your SD Card as a backup, since updates can reset, if it does, just copy it back over.
If you are script savvy, you can probably write a script to check if the files match, if they don't copy it over and include it in the /media/fat/linux/user-startup.sh startup script.
Zarkov
Posts: 32
Joined: Wed Sep 22, 2021 7:42 am
Been thanked: 2 times

Re: Setting Up A Static IP Address

Unread post by Zarkov »

Flandango wrote: Wed Sep 22, 2021 2:22 pm Network configuration is now done with dhcpcd. You will have to modify the /etc/dhcpcd.conf file to setup a static ip.
Add something like this on the bottom of the file:

Code: Select all

interface eth0
static ip_address=192.168.0.XX/24
static routers=192.168.0.X
static domain_name_servers=192.168.0.X 8.8.8.8
For DNS, you don't need to Provide more than one but if you do, just leave a space between them.
The Static IP address has the /24 for the netmask, if you don't know what your network has, then leave it as /24 as that's the most common for home networks.

As a side note, copy this file to your SD Card as a backup, since updates can reset, if it does, just copy it back over.
If you are script savvy, you can probably write a script to check if the files match, if they don't copy it over and include it in the /media/fat/linux/user-startup.sh startup script.
Thank you this helped me.
jalbarracin
Posts: 75
Joined: Fri Apr 02, 2021 9:11 pm
Has thanked: 3 times
Been thanked: 15 times

Re: Setting Up A Static IP Address

Unread post by jalbarracin »

Thank you! had a little time to understand it and change it for wireless lan:

Code: Select all

interface wlan0
static ip_address=192.168.1.222/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8
As in the example, instead of eth0, for wireless you should write wlan0
in my case my ip addresses range from 192.168.1.1 to 192.168.1.255 so I selected 222
my gateway router is on 192.168.1.1

Just sharing this modification for others to inspire
Zarkov
Posts: 32
Joined: Wed Sep 22, 2021 7:42 am
Been thanked: 2 times

Re: Setting Up A Static IP Address

Unread post by Zarkov »

Perhaps the GitHub page for network access should be updated to reflect the new way of doing static. It’s still suggesting connmanctl
kahuna
Posts: 7
Joined: Sun Sep 26, 2021 5:24 am
Been thanked: 10 times

Re: Setting Up A Static IP Address

Unread post by kahuna »

Hi there,
Quick question if I may.

I had a static IP address configured, I updated to the latest MiSTer distro and now all my custom configs are gone.
Is there a way to make them persist after upgrades?

Thanks!
User avatar
Crystal
Posts: 51
Joined: Sun May 24, 2020 8:52 pm
Has thanked: 8 times
Been thanked: 11 times

Re: Setting Up A Static IP Address

Unread post by Crystal »

kahuna wrote: Sun Sep 26, 2021 5:47 am Hi there,
Quick question if I may.

I had a static IP address configured, I updated to the latest MiSTer distro and now all my custom configs are gone.
Is there a way to make them persist after upgrades?

Thanks!
while OP cant, why not set up static lease on your router instead? if you can, i'd imagine it's the easier and more reliable solution in this case
jca
Top Contributor
Posts: 1911
Joined: Wed May 27, 2020 1:59 pm
Has thanked: 145 times
Been thanked: 454 times

Re: Setting Up A Static IP Address

Unread post by jca »

It may not always be possible. sure, it is easier using the MAC address to do it but I doubt it is more reliable.
kahuna
Posts: 7
Joined: Sun Sep 26, 2021 5:24 am
Been thanked: 10 times

Re: Setting Up A Static IP Address

Unread post by kahuna »

So, I guess there’s no way of saving your custom configuration and that to persist upgrades. Isn’t it?
I also changed the root password and the .bashrc among other small things to make it more usable for me.

Thanks!
User avatar
Crystal
Posts: 51
Joined: Sun May 24, 2020 8:52 pm
Has thanked: 8 times
Been thanked: 11 times

Re: Setting Up A Static IP Address

Unread post by Crystal »

jca wrote: Sun Sep 26, 2021 12:05 pm It may not always be possible. sure, it is easier using the MAC address to do it but I doubt it is more reliable.
why wouldnt it be reliable? if you dont change router configuration, it will be reliable. i also have a raspberry pi, where i clean upgrade the system relatively often, so its actually lot more comfortable to set it up on router, where these settings will stay, no matter what changes on client side[like de10-nano in this case]. id say its more reliable, if you can take advantage of it. maybe you are not the admin on the router where you connect, maybe you have other restriction, in which case, sure, setting up static ip on de10-nano makes sense,as an alternative[a less reliable alternative, since how mister updates are handled]
jca
Top Contributor
Posts: 1911
Joined: Wed May 27, 2020 1:59 pm
Has thanked: 145 times
Been thanked: 454 times

Re: Setting Up A Static IP Address

Unread post by jca »

I did not say it was not reliable I just said I doubted it was MORE reliable. Being more convenient does not mean more reliable.
With the new dhcpcd I just one file to copy back after a Linux update, no big deal.
User avatar
Crystal
Posts: 51
Joined: Sun May 24, 2020 8:52 pm
Has thanked: 8 times
Been thanked: 11 times

Re: Setting Up A Static IP Address

Unread post by Crystal »

if we see anything, is that static ip on mister is unreliable, if you want to use any of the updater. first and foremost, its the dhcp server's job, which probably runs on your router, to handle ip assignment and lease. its definitely more reliable to handle it on server side, instead of client side[if you can. if you cant, you dont have a choice. otherwise, do it server side]
Stupid Dufus
Posts: 157
Joined: Sun Aug 30, 2020 12:04 am
Has thanked: 98 times
Been thanked: 46 times

Re: Setting Up A Static IP Address

Unread post by Stupid Dufus »

I've got mine set to static on the router side, though after a linux update for mister a few weeks ago, the MAC address changed and had to redo that. But that's the first time it's happened to me since I got mine a year or so ago.
yoshi41
Posts: 14
Joined: Sun May 24, 2020 9:12 pm
Has thanked: 2 times
Been thanked: 6 times

Re: Setting Up A Static IP Address

Unread post by yoshi41 »

I use a couple of shell scripts to set static (and dhcp) ip and mac address. Just change the variables in the script for your network setup and run it on the linux shell. It sometimes works from the MiSTer menu, but most of the time /etc is not writeable.

What it does:

- setup /etc/network/interfaces
- setup dns server
- disable (or enable) dhcp client daemon
- setup mac address

The scripts can be found in the attached zip file.
Attachments
network_ip_static.zip
(2.43 KiB) Downloaded 494 times
gibs
Posts: 66
Joined: Sun May 09, 2021 11:04 pm
Has thanked: 8 times
Been thanked: 14 times

Re: Setting Up A Static IP Address

Unread post by gibs »

yoshi41 wrote: Sat Apr 23, 2022 10:29 am

I use a couple of shell scripts to set static (and dhcp) ip and mac address. Just change the variables in the script for your network setup and run it on the linux shell. It sometimes works from the MiSTer menu, but most of the time /etc is not writeable.

What it does:

  • setup /etc/network/interfaces
  • setup dns server
  • disable (or enable) dhcp client daemon
  • setup mac address

The scripts can be found in the attached zip file.

Thanks but from what I see, it set-up the mac address for eth0.
my issue is on wlan0.

I did the change in u-boot.txt manualy and it did not work.

yoshi41
Posts: 14
Joined: Sun May 24, 2020 9:12 pm
Has thanked: 2 times
Been thanked: 6 times

Re: Setting Up A Static IP Address

Unread post by yoshi41 »

Each wifi adapter has it‘s own unique mac (hardware) address. There is no need to change it.

The mac address for eth0 is by default the same for every MiSTer. This is a problem if you have more than one MiSTer in your network. In this case, you can assign your own unique mac address.

akeley
Top Contributor
Posts: 1441
Joined: Mon May 25, 2020 7:54 pm
Has thanked: 497 times
Been thanked: 467 times

Re: Setting Up A Static IP Address

Unread post by akeley »

I've been struggling with this for quite some time now. Nearly every time I try to log in to MiSTer via WinSCP it fails, because the IP (displayed in the OSD) is different.

I know nothing about networking, it's always been my Kryptonite, so would like to use yoshi41's script. I tried to do it from WinSCP but don't know what command to use - I only get these "not understood errors"

sshot-2023-05-22-13-55-50.png
sshot-2023-05-22-13-55-50.png (23.75 KiB) Viewed 8542 times

CRT SCR$ Project - building a collection of high-quality photos of CRT displays
CRT ART Books - retro-gaming books with authentic CRT photos

Post Reply