Static IP address

I would like a static IP address on my Pi running Raspbian. I can get this if I use an ethernet cable, but my connection is via WLAN. I have been unable to get a static address using WLAN. Should I be modifying a different file to achieve this rather than /etc/network/interfaces.

All my googling and reading only covers ETH0. Any help appreciated

Malcolm Smith

--
T M Smith 
Using an Iyonix and RISC OS 5.20 in the North Riding of Yorkshire
Reply to
T M Smith
Loading thread data ...

This works for me: # cat /etc/network/interfaces auto lo

iface lo inet loopback #iface eth0 inet dhcp iface eth0 inet static address 192.168.178.13 netmask 255.255.255.0 gateway 192.168.178.1

auto wlan0 allow-hotplug wlan0 iface wlan0 inet static address 192.168.178.14 netmask 255.255.255.0 gateway 192.168.178.1 wpa-ap-scan 1 wpa-scan-ssid 1 wpa-ssid "MySSID" wpa-psk "MyPasswd"

Reply to
Paul Berger

Another way (probably better if you have DHCP-allocated addresses on the network) is to still use DHCP on the pi, but configure the DHCP server to always allocate 192.168.178.14 to your wifi ethernet address. That way, your IP addresses are all still managed from one place, the DHCP server. Also, if you do ever need to connect your pi into another network, it will still get a valid address on that network, and work properly.

--
Andrew Gabriel 
[email address is not usable -- followup in the newsgroup]
Reply to
Andrew Gabriel

Thanks for that Paul, I will give that a try.

Malcolm

--
T M Smith 
Using an Iyonix and RISC OS 5.20 in the North Riding of Yorkshire
Reply to
T M Smith

It has worked for me also. Thanks Paul

Malcolm

--
T M Smith 
Using an Iyonix and RISC OS 5.20 in the North Riding of Yorkshire
Reply to
T M Smith

Thanks Andrew I will consider your method if I suffer problems.

Malcolm

--
T M Smith 
Using an Iyonix and RISC OS 5.20 in the North Riding of Yorkshire
Reply to
T M Smith

If that IP address is in the DHCP allocated range, don't forget to reconfigure your DHCP server to not assign it to something else.

--
Andrew Gabriel 
[email address is not usable -- followup in the newsgroup]
Reply to
Andrew Gabriel

Agreed. However, my DHCP server does not always reliably serve the same address to a given machine, so I have set static addresses on those clients I never use outside my home net. The DHCP server is configured to provide addresses 20 and up to all the other clients.

Paul

Reply to
Paul Berger

What DHCP server? Nearly all the DHCP servers I've come across have a specific option to make them always allocate the same IP address to a particular MAC address. It usually happens that A DHCP server allocates the same IP to the same MAC but it's not *forced* to unless you configure it that way.

--
Chris Green
Reply to
cl

That depends a lot on the server. "server" DHCP is often different from "consumer NAT router". Some DHCP servers in routers have a memory across reboots, others have not. Some clients remember leases and re-request the same address when they reboot, others do not. All in all it really is not reliable unless there is some explicit MAC->IP mapping in the server.

Reply to
Rob

I have not come across a consumer DHCP server (in a router, etc) which doesn't have an explicit MAC->IP mapping table, which is stored in non-volatile memory.

--
Andrew Gabriel 
[email address is not usable -- followup in the newsgroup]
Reply to
Andrew Gabriel

Some routers do this automatically for every device they encounter, others do it only on specific user request.

Reply to
Rob

My comment applies to "consumer NAT router"s! :-)

I've not come across one (and I have quite a few - several TP-Link ones, a Tenda one, a Zyxel one, a Draytek one and a couple of BT labelled ones) that doesn't allow one to specify that a particular MAC address should always be given the same IP address. They *all* have some sort of flash memory that is remembered across reboots and power cycles, otherwise they'd always need complete reconfiguration after a power cycle.

You do need to *explicitly* set the configuration to make the IP address stay the same though, they don't normally default to that.

--
Chris Green
Reply to
cl

Which is what I said, you mostly have to tell the router to do this.

--
Chris Green
Reply to
cl

But that is different from "server" DHCP. ISC DHCP remembers the MAC to IP mapping by default. You don't need to configure anything for that, nor do you have to setup the mapping yourself. There are routers that do that as well.

Reply to
Rob

[Crap DHCP severs]

Get an ASUS router, the firmware on them is pretty good, and I've had no problems setting up static addresses for everything (including several Raspberry Pi's), which have survived power cycles.

I've got a RT-ac68U and upgraded all our laptops with an Intel 7260 AC cards. Most have gigabit ethernet, but on the one which only has 100Mbit ethernet the Wireless is now faster, doing over 250Mb/s on 5GHz. It's a pitty you can't bypass the Pi's slow 100Mb networking, as a wireless-AC adaptor would also be limited by the USB bus, as is the ethernet.

---druck

Reply to
druck

I think there is something "odd" about how Raspberry's request a lease. The DHCP server here gives everyhing the same address as it had before, even over long periods of abscence but the two Raspberry's can get different address's by a simple reboot. It might be related to booting between different OS's but the MAC doesn't change...

--
Cheers 
Dave.
Reply to
Dave Liquorice

Well mine certainly gets the same IP all the time, but I have told the DHCP server that I want it that way.

--
Chris Green
Reply to
cl

Just had my Kodi (XBMC) Raspberry move IP address. We had a short power cut in the we small hours so it had the power yanked. "Short" was longer than 2 mins as the server/router/firewall had shut down. On powering it back up (its the DHCP server) the Kodi Pi got a different IP address. The Pi running a stills/timelapse webcam, that also had it's power yanked, got the same address as it had before.

--
Cheers 
Dave.
Reply to
Dave Liquorice

The DHCP/bootp/etc protocols are designed to give a very high stability in the assignments of IP addresses. Both the host and the server has as much persistent memory as hardware permits.

A client will ask for the same IP address as it had the last time, and the server should assign that, pending some arp-ing on the net to see that this address is indeed unused. The server should also keep client addresses in backing store to be reassigned when they come back.

A correctly implemented dhcp client and server will hardly ever change the IP addresses. The only instance this happens is when there is a general scarcity of IP addresses, or if a host is offline for a long time (weeks).

I have had dhcp running on a ddwrt router for 4 years now, and all the boxes keep the same IP address they had for years.

-- mrr

Reply to
Morten Reistad

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.