ofey
Posts: 152
Joined: Tue Jul 16, 2013 9:41 pm
Location: St.Gallen, Switzerland/Dublin, Ireland
Contact: Website

Setting static wlan0 ip

Thu Dec 19, 2013 12:12 pm

Hi,
I have set my pi's wlan0 ip to static
/etc/network/interfaces

Code: Select all

auto lo

iface lo inet loopback
iface wlan0 inet static
address 192.168.1.80
netmask 255.255.255.0
gateway 192.168.1.254

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
I have rebooted my pi and my router but the router's client list still gives the pi an ip of 192.168.1.6
piStaticIP.JPG
piStaticIP.JPG (26.39 KiB) Viewed 14426 times
And 192.168.1.6 is the ip I use for ssh to access my pi. I can access my pi using port forwarding to 192.168.1.6 from the LAN.
Could there be a conflict in /etc/network/interfaces with lines

Code: Select all

iface wlan0 inet static
and

Code: Select all

iface wlan0 inet manual
Is there anywhere I can go to find out what everything in /etc/network/interfaces means? Such as, what is inet, does the order of the commands matter etc?
Also why does the router not give the pi in it's client list if the pi is connected via an ethernet cable?
Any help would be greatly appreciated.
Thanks,
Shane
Pi = too much fun!

MrEngman
Posts: 3868
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Setting static wlan0 ip

Thu Dec 19, 2013 12:28 pm

Try the command man interfaces. That should show what you are after.


MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

ofey
Posts: 152
Joined: Tue Jul 16, 2013 9:41 pm
Location: St.Gallen, Switzerland/Dublin, Ireland
Contact: Website

Re: Setting static wlan0 ip

Thu Dec 19, 2013 12:32 pm

Great
Thank you.
Pi = too much fun!

MrEngman
Posts: 3868
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Setting static wlan0 ip

Thu Dec 19, 2013 12:41 pm

ofey wrote:Hi,
I have set my pi's wlan0 ip to static
/etc/network/interfaces

Code: Select all

auto lo

iface lo inet loopback
iface wlan0 inet static
address 192.168.1.80
netmask 255.255.255.0
gateway 192.168.1.254

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
I have rebooted my pi and my router but the router's client list still gives the pi an ip of 192.168.1.6
piStaticIP.JPG
And 192.168.1.6 is the ip I use for ssh to access my pi. I can access my pi using port forwarding to 192.168.1.6 from the LAN.
Could there be a conflict in /etc/network/interfaces with lines

Code: Select all

iface wlan0 inet static
and

Code: Select all

iface wlan0 inet manual
Is there anywhere I can go to find out what everything in /etc/network/interfaces means? Such as, what is inet, does the order of the commands matter etc?
Also why does the router not give the pi in it's client list if the pi is connected via an ethernet cable?
Any help would be greatly appreciated.
Thanks,
Shane
Your /etc/network/interfaces is effectively defining the wlan0 interfaces twice, with the two lines you mention above using static and manual.

To use wpa_supplicant the /etc/network/interface file would look something like

Code: Select all

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
For DHCP it would look something like

Code: Select all

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-ssid "network name"
wpa-psk "network password"
and for static I think something like

Code: Select all

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.80
netmask 255.255.255.0
gateway 192.168.1.254
wpa-ssid "network password"
wpa-psk "network name"

MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

ofey
Posts: 152
Joined: Tue Jul 16, 2013 9:41 pm
Location: St.Gallen, Switzerland/Dublin, Ireland
Contact: Website

Re: Setting static wlan0 ip

Fri Dec 20, 2013 12:12 am

Thank but unfortunately that seems to knock me off my wifi.
The following seems to work for setting wlan0 to an static ip. From Configuring WPA2 using wpa_supplicant on the Raspberry Pi I set /etc/network/interfaces to

Code: Select all

# allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet static
    address 10.1.2.20
    netmask 255.255.255.0
    network 10.1.2.0
    gateway 10.1.2.1
I did also use

Code: Select all

# sudo ifdown wlan0
# sudo ifup wlan0
Now ifconfig shows that under wlan0 inet addr: 192.168.1.80
But the raspberry pi ip on my router on still 192.168.1.5 although to VNC or ssh to my pi I have to use 192.168.1.80
I wonder why the router isn't showing the new static ip.
Maybe I need to reboot it.
Thanks,
Shane
Pi = too much fun!

ofey
Posts: 152
Joined: Tue Jul 16, 2013 9:41 pm
Location: St.Gallen, Switzerland/Dublin, Ireland
Contact: Website

Re: Setting static wlan0 ip

Fri Dec 20, 2013 12:36 am

When I reboot the router, it seems that I need to use

Code: Select all

sudo ifup wlan0
also.
This needs to be set to happen every time the pi starts.
Pi = too much fun!

User avatar
DougieLawson
Posts: 36520
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Setting static wlan0 ip

Fri Dec 20, 2013 12:38 am

ofey wrote:When I reboot the router, it seems that I need to use

Code: Select all

sudo ifup wlan0
also.
This needs to be set to happen every time the pi starts.
Add
auto wlan0
and your WiFi will be started automatically.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

ofey
Posts: 152
Joined: Tue Jul 16, 2013 9:41 pm
Location: St.Gallen, Switzerland/Dublin, Ireland
Contact: Website

Re: Setting static wlan0 ip

Fri Dec 20, 2013 1:02 am

That helps, thanks
Pi = too much fun!

MrEngman
Posts: 3868
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Setting static wlan0 ip

Fri Dec 20, 2013 5:27 am

ofey wrote:That helps, thanks
using auto wlan0 or allow-hotplug wlan0 should not make any difference so what else did you change?

In your previous post you appeared to show only part of /etc/network/interfaces and it looked like you commented out allow-hotplug wlan0 as the line had a # at the beginning. That certainly will not let the wifi automatically start up.

You also show different IP addresses for the network - 10.1.2.xx and say you get an address 192.168.1.80 which makes no sense.

And whenever you change any of the configuration you should reboot to make sure it takes effect.


MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

ofey
Posts: 152
Joined: Tue Jul 16, 2013 9:41 pm
Location: St.Gallen, Switzerland/Dublin, Ireland
Contact: Website

Re: Setting static wlan0 ip

Fri Dec 20, 2013 10:36 am

Hi,
I am trying to give my pi the static wlan0 ip 192.168.1.80 I don't understand why you say that this number doesn't make sense. Should I not simply choose an ip for my pi? Or should this number be outside the DHCP pool which is 1-200 on my router.
I want that ip to show up in my router. Although I can ssh and vnc into the pi using 192.168.1.80 the pi does not now show up on the routers client list.
clientList.JPG
clientList.JPG (28.08 KiB) Viewed 14096 times
Here is the output from ifconfig
ifconfig.JPG
ifconfig.JPG (28.69 KiB) Viewed 14096 times
and /etc/network/interfaces now has the hotplug line uncommented out. This is the complete file,
interfaces.JPG
interfaces.JPG (22.48 KiB) Viewed 14094 times
Perhaps a network ip should be included here but I don't know what that is.
N.B. I have not made any changes to wpa_supplicant.conf
Thanks,
Shane
Pi = too much fun!

MrEngman
Posts: 3868
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Setting static wlan0 ip

Fri Dec 20, 2013 10:56 am

ofey wrote:Thank but unfortunately that seems to knock me off my wifi.
The following seems to work for setting wlan0 to an static ip. From Configuring WPA2 using wpa_supplicant on the Raspberry Pi I set /etc/network/interfaces to

Code: Select all

# allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet static
    address 10.1.2.20
    netmask 255.255.255.0
    network 10.1.2.0
    gateway 10.1.2.1
I did also use

Code: Select all

# sudo ifdown wlan0
# sudo ifup wlan0
Now ifconfig shows that under wlan0 inet addr: 192.168.1.80
But the raspberry pi ip on my router on still 192.168.1.5 although to VNC or ssh to my pi I have to use 192.168.1.80
I wonder why the router isn't showing the new static ip.
Maybe I need to reboot it.
Thanks,
Shane
Try this


MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

ofey
Posts: 152
Joined: Tue Jul 16, 2013 9:41 pm
Location: St.Gallen, Switzerland/Dublin, Ireland
Contact: Website

Re: Setting static wlan0 ip

Fri Dec 20, 2013 11:00 am

Hi MrEngman,
Thanks for your reply, but is it the link I should follow there?
Shane
Pi = too much fun!

MrEngman
Posts: 3868
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Setting static wlan0 ip

Fri Dec 20, 2013 11:20 am

ofey wrote:Hi MrEngman,
Thanks for your reply, but is it the link I should follow there?
Shane
You are showing your /etc/network/interfaces with address 10.1.2.20 etc. but you then say you get address 192.168.1.80. That is what does not make sense.

MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

MrEngman
Posts: 3868
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Setting static wlan0 ip

Fri Dec 20, 2013 11:57 am

Just experimenting with static IP's.

My normal configuration uses dhcp with /etc/network/interfaces

Code: Select all

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-ssid "network name"
wpa-psk "network password"
I then changed /etc/network/interfaces to use a static IP. It works with two slightly different configurations. First is

Code: Select all

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.16.100
netmask 255.255.255.0
gateway 192.168.16.2
wpa-ssid "network name"
wpa-psk "network password"
and the other is

Code: Select all

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.16.100
network 192.168.16.255
gateway 192.168.16.2
wpa-ssid "network name"
wpa-psk "network password"
I don't use wpa_supplicant as it is unnecessary and just makes things too complicated.

You should reboot after making any changes. If you don't get a connection try using

Code: Select all

sudo ifdown wlan0
sudo ifup wlan0

MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

ofey
Posts: 152
Joined: Tue Jul 16, 2013 9:41 pm
Location: St.Gallen, Switzerland/Dublin, Ireland
Contact: Website

Re: Setting static wlan0 ip

Fri Dec 20, 2013 10:11 pm

Hi,
This is not working and I have used

Code: Select all

sudo ifdown wlan0
sudo ifup wlan0
but should I be able see the pi's ip on my router? I can't connect to my pi via ssh.
/etc/network/interfaces

Code: Select all

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet static
        address 192.168.1.80
        netmask 255.255.255.0
        gateway 192.168.1.254
wpa-ssid "blah"
wpa-psk "blah"
The DHCP pool is 192.168.1.1 to 200 as the static ip I am trying to assign to my pi is not DHCP should i be assigning an ip outside of this pool, i.e. 192.168.1.201 ?
Should I include a broadcast address in /etc/network/interfaces, ifconfig I think it is 192.168.1.255
(I should also probably be including a network ip, but I've no idea what that is.)

Code: Select all

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:65 errors:0 dropped:0 overruns:0 frame:0
          TX packets:65 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:6496 (6.3 KiB)  TX bytes:6496 (6.3 KiB)

wlan0     Link encap:Ethernet  HWaddr 00:0f:13:38:0c:a1
          inet addr:192.168.1.80  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1967 errors:0 dropped:3 overruns:0 frame:0
          TX packets:1591 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:691128 (674.9 KiB)  TX bytes:239446 (233.8 KiB
I know DHCP gives devices on the LAN ip addresses but can devices give the router their ips too.
Now I have to ask a stupid question......, actually just check something............
Does DHCP applies to both wlan0 and eth0?
Thanks,
Shane
Pi = too much fun!

MrEngman
Posts: 3868
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Setting static wlan0 ip

Fri Dec 20, 2013 11:15 pm

My router has some addresses assigned for fixed IPs, others for DHCP and others not to use at all.

I can assign any address as a fixed address and it will connect as long as it is not in the list of addresses not to use. It will still connect with the fixed address I give it even if it is in the list of addresses used by DHCP.

Which addresses you can use may depend on how your router works.

You say your wifi is not working but you show some output from command ifconfig which shows that the wifi has an address so I would expect it to be working. The information you show and what you say is happening is rather confusing.


MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

ofey
Posts: 152
Joined: Tue Jul 16, 2013 9:41 pm
Location: St.Gallen, Switzerland/Dublin, Ireland
Contact: Website

Re: Setting static wlan0 ip

Sat Dec 21, 2013 12:51 am

On my router there is a client list of all devices on the LAN. Each device's MAC address is listed. There is an option to reserve a devices ip address to the devices MAC address. So I ticked that. Then I set the static wlan0 ip on the pi to the same ip for the pi on the router. That way the router decides the pi's ip and then the pi is set to that. Hopefully it will not change now. I can ssh into pi again.
I have gone back to my original interface configuration.

Code: Select all

auto lo

iface lo inet loopback
iface wlan0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.254

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
I don't know if this is configured correctly for the next steps which are to use no-ip and I want to be able to use VNC through an ssh tunnel. But that's another days work. Then anything I do on the pi I will be able to access remotely.

Thanks,
Shane
Pi = too much fun!

ofey
Posts: 152
Joined: Tue Jul 16, 2013 9:41 pm
Location: St.Gallen, Switzerland/Dublin, Ireland
Contact: Website

Re: Setting static wlan0 ip

Sat Dec 21, 2013 1:38 am

Previously when I ssh'd into my pi I saw
[email protected]
now it's
[email protected]
So I am pretty sure the pi now has a static ip.
Pi = too much fun!

MrEngman
Posts: 3868
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Setting static wlan0 ip

Sat Dec 21, 2013 1:42 am

ofey wrote:On my router there is a client list of all devices on the LAN. Each device's MAC address is listed. There is an option to reserve a devices ip address to the devices MAC address. So I ticked that. Then I set the static wlan0 ip on the pi to the same ip for the pi on the router. That way the router decides the pi's ip and then the pi is set to that. Hopefully it will not change now. I can ssh into pi again.
I have gone back to my original interface configuration.

Code: Select all

auto lo

iface lo inet loopback
iface wlan0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.254

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
I don't know if this is configured correctly for the next steps which are to use no-ip and I want to be able to use VNC through an ssh tunnel. But that's another days work. Then anything I do on the pi I will be able to access remotely.

Thanks,
Shane
Your /etc/network/interfaces file appears to be essentially set up for two different configurations of wlan0. The first which probably will not work as there is no auto wlan0 or allow-hotplug wlan0

Code: Select all

iface wlan0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.254
and the second which will use wpa_supplicant.conf and will probably over-ride the first configuration

Code: Select all

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
One question - is your Pi a Model A as there is no eth0 setting in ifconfig?

MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

MrEngman
Posts: 3868
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Setting static wlan0 ip

Sat Dec 21, 2013 1:51 am

Have you tried

Code: Select all

auto lo

iface lo inet loopback

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.254
wpa-ssid "network name"
wpa-psk "network password"
for /etc/network/interfaces. I would expect this to work without needing to use wpa_supplicant.conf.


MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

ofey
Posts: 152
Joined: Tue Jul 16, 2013 9:41 pm
Location: St.Gallen, Switzerland/Dublin, Ireland
Contact: Website

Re: Setting static wlan0 ip

Sat Dec 21, 2013 1:57 am

I will try that configuration in the morning, 2am now.
I forgot to say in the last post that I have a Model B definitely, it's got an ethernet port.
Thanks,
Shane
Pi = too much fun!

MrEngman
Posts: 3868
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Setting static wlan0 ip

Sat Dec 21, 2013 2:13 am

To enable eth0 just add iface eth0 inet dhcp to use dhcp

Code: Select all

auto lo

iface lo inet loopback

iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.254
wpa-ssid "network name"
wpa-psk "network password"
or for a static eth0 IP use something like

Code: Select all

auto lo

iface lo inet loopback

iface eth0 inet static
address 192.168.1.xx    <-- set static IP here
netmask 255.255.255.0
gateway 192.168.1.254

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.254
wpa-ssid "network name"
wpa-psk "network password"
MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

ofey
Posts: 152
Joined: Tue Jul 16, 2013 9:41 pm
Location: St.Gallen, Switzerland/Dublin, Ireland
Contact: Website

Re: Setting static wlan0 ip

Tue Dec 24, 2013 1:35 am

Hi,
I am sorry I have not given feedback recently. But all is now working and very well too.
The interfaces file that I am using reads,

Code: Select all

auto lo

iface lo inet loopback
iface wlan0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.254
broadcast 192.168.1.255


allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
I have also successfully set up no-ip and I've been able to set the RPi Web Cam Interface.
So I am very happy with progress.
Thank you all for your help.
Shane
Pi = too much fun!

User avatar
fade2gray
Posts: 16
Joined: Fri Apr 24, 2015 2:21 pm

Re: Setting static wlan0 ip

Fri Apr 24, 2015 3:20 pm

I'm not a stranger to configuring a static ip under linux and though I could assign a static ip with outgoing connection on raspbian, I couldn't ping or ssh in.

Thanks for...
ofey wrote:

Code: Select all

# allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet static
    address 10.1.2.20
    netmask 255.255.255.0
    network 10.1.2.0
    gateway 10.1.2.1
And thanks for reminding me...
DougieLawson wrote:
ofey wrote:auto wlan0

Return to “Troubleshooting”