Rajaramesh
Posts: 10
Joined: Mon May 13, 2019 5:06 pm

Is it possible to have static IP address?

Fri May 17, 2019 9:03 am

Hi , whenever i power up Raspberry PI i am getting new ip address and i am not able to make other program work successfully, because of change in IP address. is it good to have static IP address whenever i power up Raspberry PI? if yes, can someone share the steps or links how to build static IP address?

wildfire
Posts: 451
Joined: Sat Sep 03, 2016 10:39 am
Location: Dundee, Scotland

Re: Is it possible to have static IP address?

Fri May 17, 2019 9:14 am

Depends on what you mean by static IP?

If on your own LAN then yes it's certainly possible.

If on the internet facing side then that would depend on your ISP. Some service providers offer this but it may come at an additional cost.
Shirley McGregor, (1966-2019). Always remembered. Look after Bonny Conny for me Hon. RIP.

LTolledo
Posts: 1377
Joined: Sat Mar 17, 2018 7:29 am

Re: Is it possible to have static IP address?

Fri May 17, 2019 10:58 am

All my RPi's have static IP reserved by my router.....

We need to know if you have (and in complete control of ) your own router....

but you can also specify it on the RPi itself, there are some tutorials around the forum and on the web.... just make sure its dated 2018 and up
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

drgeoff
Posts: 9251
Joined: Wed Jan 25, 2012 6:39 pm

Re: Is it possible to have static IP address?

Fri May 17, 2019 11:02 am

A search engine will lead you to many tutorials on how to get a fixed IP address for your RPi on your LAN. You will find 3 ways:

1. Leave the RPi set to get a dynamic address but configure the router to always allocate the same address.

2. edit the dhcpcd.conf file on the RPi.

3. edit the interfaces file on the RPi. Ignore that obsolete method.

User avatar
RaTTuS
Posts: 10244
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Is it possible to have static IP address?

Fri May 17, 2019 11:06 am

get your router to do it ......
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

pcmanbob
Posts: 5910
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Is it possible to have static IP address?

Fri May 17, 2019 11:09 am

There are 2 ways you can have a static IP on your local network for your pi.

1. use your router to set a persistent/reserved IP address for you pi so the router always assigns the same IP to your pi.

setup is done on your router if it supports it.

2. set a static IP on the pi its self.

To do this you have to have some addresses on your local network that are no set by the DHCP server in your router , to do this you will have to adjust the LAN address range in your router set up.

then you need to edit the dhcpcd.conf file on your pi

Code: Select all

sudo nano /etc/dhcpcd.conf
and find the lines

Code: Select all

# Example static IP configuration:
interface eth0
static ip_address=192.168.1.17/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
static routers=192.168.1.1
static domain_name_servers=192.168.1.251
and edit them as shown above inserting your own address for each entry ( do not just copy the ones in this example as they are for my LAN and may not be correct for yours )

once edited and saved you need to reboot your pi for the new address to take afect.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Rajaramesh
Posts: 10
Joined: Mon May 13, 2019 5:06 pm

Re: Is it possible to have static IP address?

Fri May 17, 2019 11:16 am

Thank you all for the details.
Actually i am connecting Raspberry PI with my mobile hotspot and PI is connected to my laptop through cable . i use advance IP search to get ip address of my PI whenever i power up the board. In this case how can i achieve static IP address.

Ernst
Posts: 1091
Joined: Sat Feb 04, 2017 9:39 am
Location: Germany

Re: Is it possible to have static IP address?

Fri May 17, 2019 11:29 am

Rajaramesh wrote:
Fri May 17, 2019 11:16 am
Thank you all for the details.
Actually i am connecting Raspberry PI with my mobile hotspot and PI is connected to my laptop through cable . i use advance IP search to get ip address of my PI whenever i power up the board. In this case how can i achieve static IP address.
Can you please provide the following information:
- output of "ip addr" (on the Pi)
- output of "cat /etc/os-release"
- output of "uname -a"
- which of the two interfaces (eth0,wlan0) needs a fixed address ?
- why are using two interfaces on the Pi, what is the purpose of the mobile hotspot ?
- how do you connect to the internet from your laptop.
The road to insanity is paved with static ip addresses

Rajaramesh
Posts: 10
Joined: Mon May 13, 2019 5:06 pm

Re: Is it possible to have static IP address?

Sat May 18, 2019 6:55 am

Ernst wrote:
Fri May 17, 2019 11:29 am

Can you please provide the following information:
Below are the details,

- output of "ip addr" (on the Pi)
ip addr(on RPi).jpg
ip addr(on RPi).jpg (129.43 KiB) Viewed 279 times
- output of "cat /etc/os-release"
.
cat-RPi release.jpg
cat-RPi release.jpg (45.69 KiB) Viewed 279 times
- output of "uname -a"
uname-RPi.jpg
uname-RPi.jpg (23.23 KiB) Viewed 279 times
- which of the two interfaces (eth0,wlan0) needs a fixed address ?
(A) i am bit confused here(eth0, wlan0). my intention here is to have one ip address whenever i want to access RPi through PUTTY / MobaXterm by connecting to laptop . it will be help full if i can have fixed for eth0 and fixed for wlan0 if possible . so i can connect RPI based on choice.

- why are using two interfaces on the Pi, what is the purpose of the mobile hotspot ?
(A) i have no router. so, i am access internet through my mobile (phone) network.

- how do you connect to the internet from your laptop
(A) through wifi ( i am access internet through my mobile (phone) network.)

Ernst
Posts: 1091
Joined: Sat Feb 04, 2017 9:39 am
Location: Germany

Re: Is it possible to have static IP address?

Sat May 18, 2019 8:11 am

The bad news: we have a problem.
The good news: something can be done although not everything.

There are a few problematic points in your configuration that may cause problems sometime in the future.
To be able to understand, and to be able to repair if necessary, a good knowledge of networking is needed.

Note: from your information I have noticed that you have configured ICS (Internet Connection Sharing) on your PC, effectively this means that your PC is functioning as a router for the Pi.

The first complexity is that you have a split "personality" Pi, this device when connected by Wifi only is configured with parameters received from your mobile hotspot (hdcp) providing the IP address and routing information. When you use the "ip route" command I suspect that it will show "192.168.43.1" as the default route with a metric of 302. What this means is that the Pi communicates with every device outside the your network (192.168.43.0) via the gateway with the address 192.168.43.1.

The next complexity is that this device when connected by Ethernet only is configured with information received from your PC (hdcp) providing the IP address and routing information. When you use the "ip route" command I suspect that it will show "192.168.37.1" as the default route with a metric of 202. What this means is that the Pi communicates with every device outside the your network (192.168.37.0) via the gateway with the address 192.168.37.1.

If we now connect the Pi to the mobile hotspot using Wifi and the PC using Ethernet then the Pi received configuration parameters from the mobile hotspot and the PC. Effectively this means the Pi will be in two networks with different addresses. But there can only be one default gateway and in this case the lowest metric will be used. What this means is that the ethernet interface with metric 202 will be used as the gateway for the internet.

Under these circumstances it will be relatively simple to assign a fixed IP address to the ethernet interface (because of ICS) but a little bit more difficult for the WiFi interface. We do not know which parameters are provided by the mobile hotspot and my guess could be wrong. Best is to connect the Pi to the mobile hotspot and to use "ip route" and "cat /etc/resolv.conf" to get the default gateway and the dns server address. I assume that the PC and the mobile hotspot will be proxy for dns, and this could be at the end of your /etc/dhcpcd.conf file for the fixed addresses:

Code: Select all

# Example static IP configuration for eth0
interface eth0
static ip_address=192.168.137.105/24
static routers=192.168.137.1
static domain_name_servers=192.168.137.1

# Example static IP configuration for wlan0
interface wlan0
static ip_address=192.168.43.188/24
static routers=192.168.43.1
static domain_name_servers=192.168.43.1
You must be aware that my signature line is no joke. If you run into problems then read this message from the beginning because your problem could be routing but it can also be caused by duplicate IP addresses because we have not taken precautions to reserve any for the Pi.
You must alway keep in mind where you are, where you want to go and how you are going to get back. What this means you have consider how a message is routed to the target system and how the reply is returned to you, what interface will be used to send and which interface will receive the reply. On some badly configured systems the result can be that Wifi only works when the ethernet is plugged in (should not happen in this case).
The road to insanity is paved with static ip addresses

Rajaramesh
Posts: 10
Joined: Mon May 13, 2019 5:06 pm

Re: Is it possible to have static IP address?

Sat May 18, 2019 2:52 pm

Ernst wrote:
Sat May 18, 2019 8:11 am
The bad news: we have a problem.
The good news: something can be done although not everything.

There are a few problematic points in your configuration that may cause problems sometime in the future.
To be able to understand, and to be able to repair if necessary, a good knowledge of networking is needed.

Note: from your information I have noticed that you have configured ICS (Internet Connection Sharing) on your PC, effectively this means that your PC is functioning as a router for the Pi.

You must alway keep in mind where you are, where you want to go and how you are going to get back. What this means you have consider how a message is routed to the target system and how the reply is returned to you, what interface will be used to send and which interface will receive the reply. On some badly configured systems the result can be that Wifi only works when the ethernet is plugged in (should not happen in this case).

HI Ernst....First-of-all thank you very much.

i gone through your post and i got to know that i need to copy the code shared by you in a file (resolv.conf) for wifi and (dhcpcd.conf) for PC on RPi, if i need static IP address when i connect with wifi / cable. correct me if i am wrong and i have no idea about networking. will there be a problem by have both IP address in the file()

To work with RPi( to write commands (or) to do coding), i have connected to PC with cable. From one of video from youtube i have configured wifi on RPi. Basically i am trying to make RPi as mediator / broker to communicate between mobile app and ESP8266 board. For this most of the time i may prefer wifi static IP address..

mobile app -->RPi -->ESP8266

and for coding purpose i will connect RPi to PC.

i have no monitor and keyboard for RPi. in this case how can i get to Know "ip route" after connecting the Pi to the mobile hotspot. can i do as below ,
1. conncet RPi to wifi(mobile hotspot)
2. conncet RPi to PC through cable(disabling wifi on PC) to get ip route of RPi
Suggest me how can i achieve.

Ernst
Posts: 1091
Joined: Sat Feb 04, 2017 9:39 am
Location: Germany

Re: Is it possible to have static IP address?

Sat May 18, 2019 3:14 pm

Rajaramesh wrote:
Sat May 18, 2019 2:52 pm

i gone through your post and i got to know that i need to copy the code shared by you in a file (resolv.conf) for wifi and (dhcpcd.conf) for PC on RPi, ....
The ONLY place where you change anything is in "/etc/dhcpcd.conf". Do not touch "/etc/resolv.conf" or "/etc/networks/interfaces".
Rajaramesh wrote:
Sat May 18, 2019 2:52 pm
i have no monitor and keyboard for RPi. in this case how can i get to Know "ip route" after connecting the Pi to the mobile hotspot. can i do as below ,
1. conncet RPi to wifi(mobile hotspot)
2. conncet RPi to PC through cable(disabling wifi on PC) to get ip route of RPi
Suggest me how can i achieve.
The route is not important except that it has to be correct. The default route is set with the line "static routers=" in dhcpcd.conf. I suspect that the gateway address on your mobile hotspot is 192.168.43.1.
You can find out the settings on your PC connected to the WiFi with the ipconfig command.

Be warned that we are discussing a very difficult subject, on your PC there will be a default gateway pointing to your mobile access point, on the Pi there will be a default gateway pointing to the mobile access point AND a default gateway pointing to the PC.
The road to insanity is paved with static ip addresses

Return to “Beginners”