wroachbarrette
Posts: 5
Joined: Fri Jun 07, 2013 5:00 pm

How do I set up a static ip address on wifi?

Mon Jul 08, 2013 2:42 pm

Hello, I know that there have been a few articles posted on this already but being rather new to the raspberry pi I don't know exactly how to fill out the correct information to make this work properly. I need to assign a static IP address to a raspberry pi that's connected to a linksys router, ive been using the following config file so far and dont know what to add to this to give the pi a static ip address. Any help would be greatly appreciated

this is my /etc/network/interfaces file

Code: Select all

auto lo

iface lo inet loopback
iface eth0 inet dhcp

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
     wireless-essid linksys
is there some way I can add code to this to give it a static ip address?

gobstopper
Posts: 19
Joined: Sun Jun 30, 2013 9:08 am
Location: Essex - UK

Re: How do I set up a static ip address on wifi?

Mon Jul 08, 2013 3:04 pm

You can substitute as necessary, but working on the premise that most home routers will dish out a 192.168.1.x address to a machine requesting an address over DHCP, and that the router itself is 192.168.1.1, this is what I'd do.

Find the entry "iface wlan0 inet dhcp", substitute "dchp" with "static" and then add the following lines immediately below so that it looks like this:-

Code: Select all

iface wlan0 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
network 192.168.1.0
broadcast 192.168.1.255
I'm fairly new to this myself and I'm not sure if by switching the interface into static mode you'll then need to set your DNS address manually as well.

If so, edit /etc/resolv.conf and add a "server" entry to the file:-

Code: Select all

search mydomain.com
server 8.8.8.8
Substitute "mydomain.com" with your domain name (or remove completely) and if you have a preferred DNS server put its address in place of 8.8.8.8.

The either re-boot, or re-start the networking services.

Code: Select all

sudo ./etc/init.d/networking restart
Hope that helps.
-Phil.

User avatar
RaTTuS
Posts: 10801
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: How do I set up a static ip address on wifi?

Mon Jul 08, 2013 3:05 pm

personally I'd do it on the router
that way - it is more transferable to other locations
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

wroachbarrette
Posts: 5
Joined: Fri Jun 07, 2013 5:00 pm

Re: How do I set up a static ip address on wifi?

Mon Jul 08, 2013 4:53 pm

gobstopper wrote:You can substitute as necessary, but working on the premise that most home routers will dish out a 192.168.1.x address to a machine requesting an address over DHCP, and that the router itself is 192.168.1.1, this is what I'd do.

Find the entry "iface wlan0 inet dhcp", substitute "dchp" with "static" and then add the following lines immediately below so that it looks like this:-

Code: Select all

iface wlan0 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
network 192.168.1.0
broadcast 192.168.1.255
I'm fairly new to this myself and I'm not sure if by switching the interface into static mode you'll then need to set your DNS address manually as well.

If so, edit /etc/resolv.conf and add a "server" entry to the file:-

Code: Select all

search mydomain.com
server 8.8.8.8
Substitute "mydomain.com" with your domain name (or remove completely) and if you have a preferred DNS server put its address in place of 8.8.8.8.

The either re-boot, or re-start the networking services.

Code: Select all

sudo ./etc/init.d/networking restart
Hope that helps.
-Phil.
Thanks for the reply. I was able to assign a static ip address by modifying the code I already had with your code, the working code is as follows

Code: Select all

auto lo

iface lo inet loopback
iface eth0 inet dhcp

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.111 
netmask 255.255.255.0
gateway 192.168.1.1
network 192.168.1.0
broadcast 192.168.1.255
     wireless-essid linksys

BAReese
Posts: 1
Joined: Mon Sep 30, 2013 4:16 pm

Re: How do I set up a static ip address on wifi?

Mon Sep 30, 2013 4:23 pm

I'm still pretty new to Linux, but my preferred method to handle static IP addresses is to use the Router's built-in functionality (if it exists). Most Linksys and D-Link routers have Static/Reserved IP functionality. This usually requires getting the MAC ID of the wireless device used, but that can be easily found on the DHCP lease page. This also allows you to keep the device (in this case Raspberry Pi) setup in DHCP mode and it will still connect to other networks/subnets without any problems.

This is fairly simple to setup and usually doesn't require any special commands.

sid_3284
Posts: 6
Joined: Fri Dec 20, 2013 7:33 pm

Re: How do I set up a static ip address on wifi?

Fri Dec 20, 2013 7:41 pm

I have used this code but when I do ssh to my raspberry pi which ip should i use to ssh?
I tried ssh to the ip that i gave in the address in interfaces file.

But that request used to time out.

$ ssh pi@192.168.1.104
ssh: connect to host 192.168.1.104 port 22: Operation timed out

User avatar
DougieLawson
Posts: 41898
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: How do I set up a static ip address on wifi?

Fri Dec 20, 2013 8:32 pm

sid_3284 wrote:I have used this code but when I do ssh to my raspberry pi which ip should i use to ssh?
I tried ssh to the ip that i gave in the address in interfaces file.

But that request used to time out.

$ ssh pi@192.168.1.104
ssh: connect to host 192.168.1.104 port 22: Operation timed out
Are you sure that's the assigned IP address?
Try looking at the LAN devices page in your router.
Or install Fing to scan your LAN and find your Pi.
Are you sure sshd is running and listening on port 22?
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

flyboy12
Posts: 2
Joined: Wed Nov 12, 2014 1:39 pm
Location: Louisville KY
Contact: Website

Re: How do I set up a static ip address on wifi?

Wed Nov 12, 2014 1:45 pm

How do I determine the IP for the network line? I am on a corporate network if that makes any difference....

Thanks!

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: How do I set up a static ip address on wifi?

Wed Nov 12, 2014 2:37 pm

Do a bit of lateral thinking with Gobstopper's reply.....
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

User avatar
DougieLawson
Posts: 41898
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: How do I set up a static ip address on wifi?

Wed Nov 12, 2014 3:18 pm

flyboy12 wrote:How do I determine the IP for the network line? I am on a corporate network if that makes any difference....

Thanks!
You don't need to. Just don't bother adding those "network" and "broadcast" lines, they aren't needed (they can be easily calculated from the ip address and the netmask).
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: How do I set up a static ip address on wifi?

Wed Nov 12, 2014 4:54 pm

flyboy12 wrote:How do I determine the IP for the network line? I am on a corporate network if that makes any difference....

Thanks!
Unless the network team have given permission, it is most likely against company policy to add non-authorised devices to the network (especially if you have a static ip set).

bowej195
Posts: 5
Joined: Mon Mar 16, 2015 2:07 pm

Re: How do I set up a static ip address on wifi?

Mon Mar 16, 2015 7:09 pm

Will a static IP work, in any cases, at another network? If I set my Pi up with a static IP will I have to change that every time I go to another network or will it still work there.

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: How do I set up a static ip address on wifi?

Mon Mar 16, 2015 7:55 pm

bowej195 wrote:Will a static IP work, in any cases, at another network? If I set my Pi up with a static IP will I have to change that every time I go to another network or will it still work there.
Almost certainly yes you will have to change it.

lockon
Posts: 4
Joined: Sat Jul 11, 2015 8:37 pm

Re: How do I set up a static ip address on wifi?

Sat Jul 11, 2015 8:39 pm

In case you come across this thread and can't get the static IP config to work, please delete all existing leases!!!

sudo rm /var/lib/dhcp/*
sudo reboot

and, viola! your static IP will be set. I was tearing my hair out till I figured this out.

User avatar
ds18s20
Posts: 83
Joined: Fri Dec 23, 2011 5:44 am
Location: San Francisco

Re: How do I set up a static ip address on wifi?

Wed Sep 02, 2015 3:43 am

Has anyone experienced the so often discussed bug that sudo rm /var/lib/dhcp/* doesn't do it and there is a secondary kick somewhere which still runs the dhcp client daemon and the RP gets 2 addresses?

Where is that secondary location which runs the dhcp client?

The fixes work but they work by suggesting doing the IP change from the GUI which then properly updates all undocumented locations that a client dhcp is run from. I just need to know where that is?

Thanks

http://www.modmypi.com/blog/tutorial-ho ... ip-address

User avatar
rpdom
Posts: 19280
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: How do I set up a static ip address on wifi?

Wed Sep 02, 2015 5:16 am

The normal place to set static IP is in /etc/network/interfaces, but that still gives you a DHCP address as well if you have dhcpcd5 installed. In that case the palce to set it is in /etc/dchpcd.conf with something like this (untested)

Code: Select all

interface wlan0
static ip_address=192.168.1.20
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: How do I set up a static ip address on wifi?

Wed Sep 02, 2015 6:20 am

rpdom wrote:The normal place to set static IP is in /etc/network/interfaces, but that still gives you a DHCP address as well if you have dhcpcd5 installed. In that case the palce to set it is in /etc/dchpcd.conf with something like this (untested)
-a- static IP in /etc/network/interfaces is not the "normal" place, its the OLD place b4 there was a DHCPCD5 installed by RPI.ORG.

-b- now ( after @knute ) we do it in /etc/dhcpcd.conf but that requires that /etc/network/interfaces is changed back to
iface wlan0 inet manual

-c- if we want configure the wlan login in /etc/network/interfaces
wpa-ssid "my-wlan"
wpa-psk "We_Love_RPi"
we should remove the line about "wpa-conf" there.

myusername
Posts: 6
Joined: Fri Nov 06, 2015 9:00 pm

Re: How do I set up a static ip address on wifi?

Tue Dec 08, 2015 12:44 am

If i have more than 1 pi on the same remote network and i want all to automatically set their own static ip on first boot, and save the ip as a variable so I can send it to an access database online using odbc (So i can use the ip to later send files to the correct pi), is there a suitable code to set and store a unique static ip automatically?
Thanks for any advice.

Return to “Beginners”