Page 1 of 1

giving the wlan0 a static ip address

Posted: Mon Mar 31, 2014 12:46 am
by wouter1
hi,

i have spent 4 hours to get my tp-linkwn725 visible in the wifi-config....
now it says when i start browsing with midori unable to resolve hostname.
if have found out that you need to give the pi a static ip address.
main adress is on my router... i guess but how about the netmask, gateway, network and broadcast?
please some insight...

regards,

Wouter

Re: giving the wlan0 a static ip address

Posted: Mon Mar 31, 2014 1:59 am
by Tarcas
netmask, gateway, network and broadcast
Netmask will be the same as on other devices on your network. Usually 255.255.255.0

Gateway will always be the IP of your router.

Network depends on your IP and netmask. If the netmask is all 255s and 0s, it's easy. Any octet where there's a 255, the network address is the same as the IP address. For octets where the netmask has a 0, the network has a 0. If your netmask is not all 255s and 0s, paste the IP and netmask here and someone can do the math for you.

Broadcast also depends on the IP and netmask. Assuming the netmask is all 255s and 0s, find the network, but for any octet where the network has a 0, replace it with a 255. Again, if your netmask is not all 255s and 0s, paste the IP and netmask here and someone can do the math for you.

Re: giving the wlan0 a static ip address

Posted: Mon Mar 31, 2014 5:11 am
by Richard-TX
That is really a loaded question. A lot depends on how your local lan is configured. A good place to look is on your internet router. The configuration for most routers for a LANs is an 8 bit /24 bit subnetting scheme.
Let's say that the router sets up your local lan with a 192.168.2.0 network.
That means you can have a possible 254 host addresses. So here is how that translates to your Rpi setup.
broadcast 192.268.2.255
gateway router-ip-address
netmask 255.255.255.0

If is unlikely that your router would set up your local lan as anything other than a 8/24 bit network .

Re: giving the wlan0 a static ip address

Posted: Mon Mar 31, 2014 8:47 pm
by DougieLawson
Isn't it best to start by looking at the network config that DHCP gives you.

ifconfig -a
route -n

Or look at a Windows machine with
ipconfig /all

That gives you all the info you need to get started with assigning a static address (although you may need to look at the DHCP settings on your router to reserve a range of IP addresses that won't be dynamically assigned).

If your router can do static IP based on MAC address then it's much easier to use that. (I've never met a router that can do that stuff - we can but hope.)

This all gets easier with IPv6 where hardware MAC forms part of the assigned IPv6 address automagically so every machine gets a fixed IPv6 within the /64 network prefix.

BTW, do NOT code broadcast in /etc/network/interfaces it's much better to leave it out as Linux is perfectly capable of working it out from ip addr, gateway & netmask.

Re: giving the wlan0 a static ip address

Posted: Thu Apr 03, 2014 7:06 pm
by mefd5791
Okay so I've been trying to set up a static ip on my rpi as well, and this post is the first post that's telling me that the network and broadcast depend on the netmask.... and that's a problem because my netmask is 255.255.252.0. my gateway (router ip) is 10.2.12.1

Can someone help?

Re: giving the wlan0 a static ip address

Posted: Thu Apr 03, 2014 7:38 pm
by DougieLawson
Why do you need a /22 network are there really 1024 stations on your LAN segment?

The basics are just the same
netmask
gateway
& local ip.

Everything should just work itself out.

Base address 10.2.12.0
Broadcast 10.2.15.255
Host mask 0.0.3.255
Next base 10.2.16.0

As long as the gateway is somewhere between 10.2.12.1 and 10.2.15.254 it will be OK.