Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

static ip for specific essid

Linux Kernel, Network, and Services configuration.
Message
Author
morgon
Posts: 189
Joined: 2010-08-28 03:04

static ip for specific essid

#1 Post by morgon »

Hi,

I sometimes change the mac-address of my laptop's wireless interface that has the side-effect that when I forget to change it back it get's assigned a new ip from my router at home.

So what I want is a way to configure a fixed ip for my laptop whenever it is connected to my network at home (identified by essid), but to use dhcp everywhere else.

How can I do this?

Many thanks!

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: static ip for specific essid

#2 Post by bw123 »

I know how to do it on stretch with networkmanager, and at least two, maybe three ways with ifupdown. It's probably possible with systemd-networkd and wicd or connman too. Do you want people to explain all the different methods?
resigned by AI ChatGPT

morgon
Posts: 189
Joined: 2010-08-28 03:04

Re: static ip for specific essid

#3 Post by morgon »

Good point.

I am not using network-manager, so I had hoped of some way to do it by editing /etc/network/interfaces and/or /etc/wpa_supplicant/wpa_supplicant.conf

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: static ip for specific essid

#4 Post by bw123 »

/usr/share/doc/wpasupplicant/README.modes.gz is the goto doc, and /usr/share/doc/wpasupplicant/examples/wpa-roam.conf is the goto ref for managing wireless interfaces with ifupdown.

This short guide is really helpful if you take your time and read the above carefully.
https://xrunhprof.wordpress.com/2009/09 ... on-debian/
One idea is to assign sort of a "tag" or alias using "id_str="whatever" in the wpa_supplicant.conf, which matches an iface alias in the interfaces file.

Look for the part that says...
For each network, you may specify a special option 'id_str'. It should be set to
a simple text string. This text string forms the basis for network profiling;
resigned by AI ChatGPT

morgon
Posts: 189
Joined: 2010-08-28 03:04

Re: static ip for specific essid

#5 Post by morgon »

That's what I tried to do (using id_str in wpa_supplicant and a corresponding entry in /etc/network/interfaces) but it did not work.

But I guess I'll have another look if it should work - it may very well be I was simply too stupid...

shep
Posts: 423
Joined: 2011-03-15 15:22

Re: static ip for specific essid

#6 Post by shep »

I think you can combine:
https://wiki.debian.org/NetworkConfigur ... e_manually

with

https://wiki.debian.org/WiFi/HowToUse#W ... d_WPA2-PSK

In /etc/network/interfaces

Code: Select all

auto ZZZZ
    iface ZZZZ inet static
        address 192.0.2.7
        netmask 255.255.255.0
        gateway 192.0.2.254
        wpa-ssid XXXXXXXXXXX
        wpa-psk  XXXXXXXXXX
In Debian you can usually leave /etc/wpa_supplicant.conf alone. The links above also help to determine your device name (ZZZZ) and set up DNS resolution.

morgon
Posts: 189
Joined: 2010-08-28 03:04

Re: static ip for specific essid

#7 Post by morgon »

I simply cannot get it to work.

This how I do it currently: I have this in /etc/network/interfaces

Code: Select all

allow-hotplug wlp2s0
iface wlp2s0 inet dhcp
    wpa_conf /home/mh/my_config/wpa_supplicant.conf
And I can bring it up with "ifup wlp2s0".
This uses dhcp everywhere.

Now I want a static address for essid "mh". So I had a look at https://wiki.debian.org/WPA and this is what I came up with:

In wpa_config.conf I do this:

Code: Select all

network={
ssid="mh"
scan_ssid=1
key_mgmt=WPA-PSK
proto=WPA2
psk="xxxxxxxxx"
id_str="mh"
}
And I change /etc/network/interfaces to:

Code: Select all

allow-hotplug wlp2s0
iface wlp2s0 inet manual
    wpa_conf /home/mh/my_config/wpa_supplicant.conf

iface mh inet static
   address 192.168.0.111
   gateway 192.168.0.1
   netmask 255.255.255.0

iface default inet dhcp
So "inet dhcp" changes to "inet manual" and then I have the stanzas for my special case and the default.

This is how I understand https://wiki.debian.org/WPA, yet it does not work.

What am I doing wrong?

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: static ip for specific essid

#8 Post by bw123 »

I've never used wpa_conf in interfaces file, and can't find it quickly, what is this?
wpa_conf /home/mh/my_config/wpa_supplicant.conf
What documentation did you use to set that up? Have you tried wpa-roam for manual method?

Also. is the filename wpa_config.conf or wpa_supplicant.conf? It's easy to get conf files mixed up, usually best IMO to stick to the default/documented name and leave it in one location under /etc or /etc/wpa_supplicant to make things simpler to rememebr. Six months from now, you'll likely forget half of what you did/

You will have to define the ctrl interface also, read here...
/usr/share/doc/wpasupplicant/README.Debian.gz 11476/16384+

NOTE: it is critical that the used wpa_supplicant.conf defines the location of
the 'ctrl_interface' so that a communication socket is created for the
wpa_cli (wpa-roam daemon) to attach.
wpa is really a confusing mess of underscores and dashes... take your time. You can't make one error anywhere in the conf or interfaces file.

It's just the way it is. Nobody can fix it because all the smart people done died.
resigned by AI ChatGPT

morgon
Posts: 189
Joined: 2010-08-28 03:04

Re: static ip for specific essid

#9 Post by morgon »

Here is a documentation for wpa_conf in /etc/network/interfaces:

https://wiki.debian.org/WiFi/HowToUse#wpa_supplicant

And I never used wpa-roam, mybe this is a missing piece...

As for the filename it should not really matter, all that matters is that the filename you configure in /etc/network/interfaces exists and contains a valid wpa_supplication configuration.

But I'am using the standard file name of "wpa_supplicant.conf", which ususally is in /etc/wpa_supplication/wpa_supplicant.conf.

But my problem has nothing to do with this as this is the one line of the config that does not change when I try to configure my static ip and everything works if I revert to what it was before (with excatly this wpa_conf line).

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: static ip for specific essid

#10 Post by bw123 »

I've read your prior posts, and I realize you can be a little difficult. Show me where the word "wpa_conf" is mentioned? It would help if you would quote it for clarity, I drink a little....
resigned by AI ChatGPT

morgon
Posts: 189
Joined: 2010-08-28 03:04

Re: static ip for specific essid

#11 Post by morgon »

This is an exerpt from the link above:
WPA-EAP

For networks using EAP-TLS, you are required to establish a wpa_supplicant configuration file and provide the client-side certificate. An example WPA2-EAP configuration file can be found at /usr/share/doc/wpasupplicant/examples/wpa2-eap-ccmp.conf.

Once available, reference your configuration file in /etc/network/interfaces. For example:

auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

More information can be found in the wpa_supplicant.conf(5) man page. A fully-commented wpa_supplicant configuration file example is at /usr/share/doc/wpasupplicant/README.wpa_supplicant.conf.gz.
I grant you that this is not really a documentation, but more an example but this is what I have been using for years (I can't remember where I got it from originally).

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: static ip for specific essid

#12 Post by Head_on_a_Stick »

morgon wrote:

Code: Select all

iface mh inet static
   address 192.168.0.111
   gateway 192.168.0.1
   netmask 255.255.255.0
"mh" is not an interface ("iface") name so that stanza is nonsense.

I can assign specific IP addresses based on the MAC address of the hardware in the router's configuration, have you tried that?
deadbang

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: static ip for specific essid

#13 Post by bw123 »

^^ Going to your router config seems a really good idea, since documentation seems to be lacking so this can be easily setup. That might work unless you are using random MAC, and the post asked for how to do it with network name specifically.

I used the wrong term, it's not an 'alias' the 'mh' definition in interfaces file that matches the "id_str=mh" in the wpa_supplicant.conf is really is a 'logical' iface?

Code: Select all

$ man interfaces | grep -A7 'ifup  is  normally'
       ifup  is  normally  given a physical interface name as its first non-option argu‐
       ment.  ifup also uses this name as the initial logical  name  for  the  interface
       unless  it  is  accompanied by a  suffix of the form =LOGICAL, in which case ifup
       chooses LOGICAL as the initial logical name for the interface.  It then maps this
       name,  possibly  more  than  once according to successive mapping specifications,
       until no further mappings are possible.  If the resulting name  is  the  name  of
       some defined logical interface then ifup attempts to bring up the physical inter‐
       face as that logical interface.  Otherwise ifup exits with an error.
ANyway... this is not that complicated I use it all the time. But maybe you could try networkmanager, or if you want to stick with ifupdown, use wpa_cli or wpa_gui to create the conf and connect the wireless?
resigned by AI ChatGPT

morgon
Posts: 189
Joined: 2010-08-28 03:04

Re: static ip for specific essid

#14 Post by morgon »

Head_on_a_Stick wrote:
"mh" is not an interface ("iface") name so that stanza is nonsense.
It is a logical interface - it corresponds to an entry in the wpa_supplicant configuration
Head_on_a_Stick wrote:
I can assign specific IP addresses based on the MAC address of the hardware in the router's configuration, have you tried that?
Hear, hear.
Had you read my posts you would know that I want a solution for a device that changes it's mac-address. That's the whole point of this excercise.

Sorry to be blunt, but don't know what you are talking about and "answer" posts you don't understand (and I am sure you have not even bothered to read).

Would you mind to keep your "expertise" for yourself and stay out of this thread?

User avatar
ralph.ronnquist
Posts: 342
Joined: 2015-12-19 01:07
Location: Melbourne, Australia
Been thanked: 6 times

Re: static ip for specific essid

#15 Post by ralph.ronnquist »

You could probably use a "mapping" declaration in the interfaces file, and have a script for an on-the-spot determination of which logical name to use for the physical interface. As I haven't used this myself, I would point you at the man page (esp the MAPPINGS section) and the associated example for details (/usr/share/doc/ifupdown/examples/network-interfaces.gz). Perhaps a decision logic script using iwlist, and then the alternative iface set ups for alternative logical names.

Note that the default logical name for an interface is the interface name itself (and not the name "default").

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: static ip for specific essid

#16 Post by Head_on_a_Stick »

morgon wrote:
Head_on_a_Stick wrote:
"mh" is not an interface ("iface") name so that stanza is nonsense.
It is a logical interface - it corresponds to an entry in the wpa_supplicant configuration
Ah, I see, my apologies.
morgon wrote:
Head_on_a_Stick wrote:
I can assign specific IP addresses based on the MAC address of the hardware in the router's configuration, have you tried that?
Hear, hear.
Had you read my posts you would know that I want a solution for a device that changes it's mac-address.
Yes but unless you are using randomised MAC addresses then you will only have two different addresses for your machine so can you not assign both as you want?
morgon wrote:Sorry to be blunt, but don't know what you are talking about and "answer" posts you don't understand (and I am sure you have not even bothered to read).
Yes, I do that sometimes, it's true... I do always read them though :P
morgon wrote:Would you mind to keep your "expertise" for yourself and stay out of this thread?
Pro tip: if you don't like a post then just ignore it.
deadbang

morgon
Posts: 189
Joined: 2010-08-28 03:04

Re: static ip for specific essid

#17 Post by morgon »

Head_on_a_Stick wrote: Yes but unless you are using randomised MAC addresses
That is exactly the problem at hand.

I sometimes change my laptop's mac-address to a random value. Sometimes I change it back, sometimes I forget it.

But when connected to my network at home I nevertheless want to use the same ip, regardless of the mac-address.

My problem: I cannot make it work when I follow the documentation (at least the way I understand it).

With that out of the way this would be your time to make some sensible contribution.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: static ip for specific essid

#18 Post by Head_on_a_Stick »

morgon wrote:this would be your time to make some sensible contribution.
:D

Firstly, always include *all* of the relevant information in the OP to stop wasting people's time — if you had stated that you randomise the MAC address in the first post then I wouldn't have made my router suggestion.

Secondly, have you checked the logs to see why the id_str method "didn't work"? Have you tried running `ifup mh` to see if any errors are returned?
deadbang

morgon
Posts: 189
Joined: 2010-08-28 03:04

Re: static ip for specific essid

#19 Post by morgon »

Firstly if I say "I change my mac address" and give no further information it (for me at least) implies it is random.

It is a bit ritch from someone that has admitted that he "answers" posts without having read them first to criticize other people's posts....

Then I have (in the configuration above) tried both "ifup wlp2s0" "ifup mh".

I get no error (at least none is reported on the command line - if I remember correctly - I am not on my laptop at the moment) but it did not change the network configuration as I want it.

In both cases (again if I remember correctly) no ips at all have been assigned - not the static one I wanted and no via dhcp.

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: static ip for specific essid

#20 Post by bw123 »

You're probably just not ready, sometimes that happens to me. Sounds crazy, but sometimes I have a goal on linux to understand some "thing" and I have to put it on the back burner for awhile. The good news is, there's usually at least one alternative way to get work done.

Try networkmanager, it's easy. When you come back to ifupdown, read the links. Check spelling, remember that "wpa_conf" and "wpa-conf" are different, even if the undocumented way has always worked before, it won't always work.

I apologize for helping you create a confusing thread, that's the last thing I want, or another personal attack thread. Please don't go there, it's not a contest, we should work together.

L8r,
bw
resigned by AI ChatGPT

Post Reply