kumkum488
Posts: 3
Joined: Mon Oct 07, 2013 2:13 am

networking - static ip and dhcp

Thu Nov 14, 2013 6:31 pm

hello,
i got my pi and managed to set it to temporarily use dhcp from my router thru the "WIFI config" utility.
Eventually, i hope to disable dhcp on my router and assign an ip address to the pi.

i am trying to configure the pi as follows:
a) use a static ip adress when connected at home
b) use any ip address assign by a dhcp server when out of the house

im new to linux. i have also tried various setting based on what i have read on the internet. And have to reformat my pi several times.

i would appreciate if anyone could lend a helping hand.

thank you

PiAnAnXa
Posts: 1
Joined: Thu Nov 14, 2013 9:23 pm

Re: networking - static ip and dhcp

Thu Nov 14, 2013 9:35 pm

A static IP can be set with following command:

Code: Select all

sudo ifconfig eth0 192.168.42.1
If you want to have this persistent you need to change the file /etc/network/interfaces
Replace this:

Code: Select all

iface eth0 inet dhcp
by

Code: Select all

iface eth0 inet static
  address 192.168.42.1
  netmask 255.255.255.0

User avatar
svenix
Posts: 31
Joined: Sat Mar 02, 2013 10:01 am
Location: Göteborg Sweden

Re: networking - static ip and dhcp

Fri Nov 15, 2013 10:06 am

You could also just leave your Pi in the DHCP setting and instead configure your home router to assign a specific IP-adress to your Pi:s MAC-adress.
That way you would always have the same IP at home and use DHCP in other places.

User avatar
r4049zt
Posts: 113
Joined: Sat Jul 21, 2012 1:36 pm
Contact: Website

Re: networking - static ip and dhcp

Fri Nov 15, 2013 11:06 am

The following worked for me.

At the pi do nothing. It gets its ip from dhcp, from whatever network equipment is connected.

Pull out the cable from your DHCP router to the internet as you don't want the mafia to see what you are doing.
At your home DHCP router, login using the admin user and password. This can be done from a Windows or Linux PC. I sometimes though not always got the pi to do this in a browser after startx.
One way to login to your router is to open a browser and type in its IP address;
192.168.0.1 is the most common default.
The router password should be printed in the instructions which came with it.
Whilst off internet, you most certainly want to change from the default password to something of your own choosing.
Once logged in you can change its third number to anything that you like in the range 0 to 200 such as
192.168.99.1 If you make that change then you should switch off everthing and reboot for it to take effect.

Log in again. Some DHCP routers through their web page admin interface can "list connected devices" though the exact label of the button to click may vary. You should recognise one of these as your pi and it may be
192.168.99.101
or similar.

Your router admin interface, if it is like mine, should have a way to "set a static IP address for the MAC addresss of your pi. Here you can enter the fixed ip address which you want for the pi at home such as
192.168.99.88
That last number should be in the range decimal 101 to 199 in order for windows to be able to find it or 1 to 99 if you want to keep it out of sight of some windows defaults.

Logout and reboot the pi for this to take effect.
At the command prompt on the pi, type and enter ifconfig.
The first line of that should show your pi at the ip address sent to it by the router.
If you'd chosen the fixed one then it will show
192.168.99.88

Your pi is in its default setting; to obtain by DHCP an address, and if booted whilst plugged in at home it will get the static ip address which you set the router to deliver. I hope that this helps.

klricks
Posts: 7134
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: networking - static ip and dhcp

Fri Nov 15, 2013 1:38 pm

kumkum488 wrote:hello,
i got my pi and managed to set it to temporarily use dhcp from my router thru the "WIFI config" utility.
Eventually, i hope to disable dhcp on my router and assign an ip address to the pi.

i am trying to configure the pi as follows:
a) use a static ip adress when connected at home
b) use any ip address assign by a dhcp server when out of the house

im new to linux. i have also tried various setting based on what i have read on the internet. And have to reformat my pi several times.

i would appreciate if anyone could lend a helping hand.

thank you
If you turn off DHCP on your router, then you will have to configure every computer/device in your house for static IP's.
Normally you would leave DHCP on and configure any static addresses outside the DHCP range.
As others have said... use IP to MAC address reservations instead of static. (If your router supports that).
Here is how I set up my Linksys router.. others are similar:
http://blackeagle.duckdns.org:86/Comp/RPi/DHCP.html
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

mumikejohnson
Posts: 2
Joined: Fri Nov 15, 2013 4:19 pm

Re: networking - static ip and dhcp

Fri Nov 15, 2013 5:32 pm

You can also do this by modifying the \etc\network\interfaces and \etc\wpa_supplicant\wpa_supplicant.conf files. Try these steps:
**All network addresses will need to reflect your own network**
d. Advanced Wireless Setup (Static IP Addresses and Multiple Networks)
i. Power off your RPi
ii. Insert your wireless network adapter into one of the USB ports on the RPi
iii. Power on the RPi
iv. Open LXTerminal from the desktop
1. Type sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
a. You will need to add the following for each wifi network you want to configure
network={
ssid=”wifinetworkname”
psk=”yourwifipassword”
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
auth_alg=OPEN
id_str=”madeupID”
}

c. When done, type ctrl+c
d. Type y
e. Hit Enter
2. Type sudo nano /etc/network/interfaces
a. After the line allow-hotplug wlan0 add a new line
b. auto wlan0
c. For each network defined in the wpa_supplicant.conf file you will need to add the static network network address information section
iface idstring_from_wpa_file inet static
address 192.168.1.200
netmask 255.255.255.0
network 192.168.1.0
gateway 192.168.43.5

e. Type ctrl+x
f. Type y
g. Hit Enter
3. Type sudo reboot to reboot the RPi
v. Open LXTerminal from the desktop
1. Type ping google.com and hit enter
a. If a bunch of response lines show up then your network is configured correctly
b. If a bunch of no response error, or unknown host error lines then you need to review your configuration files to make sure your information is correct

Return to “Beginners”