doni49
Posts: 94
Joined: Wed Jan 23, 2013 4:59 pm

Create Static IP Address for Ethernet in Raspian?

Sat Jun 01, 2013 12:33 am

I've seen documentation on assigning a Static IP to a WiFi connection -- but that's WiFi not ethernet. I've seen a thread about assigning a Static IP to an ethernet connection -- but upon investigation, that thread was for Arch and the file it says to edit doesn't exist in Raspian (at. least not in what I downloaded/installed).

I want/need to set this up for SSH access so I need it to have Static IP and I really don't want to put WiFi on it.

Thanks!

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Create Static IP Address for Ethernet in Raspian?

Sat Jun 01, 2013 1:18 am

I assume you've tried the obvious:

Code: Select all

ifconfig eth0 w.x.y.z
Did it work?
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

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

Re: Create Static IP Address for Ethernet in Raspian?

Sat Jun 01, 2013 1:56 am

I set up my router for IP reservation to MAC address so that the router (DHCP) always gives my RPi the same IP address. Pretty easy to do and there is no configuration to do in the RPi.

Here is how I did this on my Linksys router others are similar:
http://64.13.91.137:86/Comp/RPi/DHCP.html

Does not matter if WIFI or wired it's the same setup.
Last edited by klricks on Sat Jun 01, 2013 1:59 am, edited 1 time in total.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

sdjf
Posts: 1395
Joined: Fri Mar 16, 2012 5:20 am
Location: California
Contact: Website

Re: Create Static IP Address for Ethernet in Raspian?

Sat Jun 01, 2013 1:58 am

This command will do it but only until the next boot/reboot:

ifconfig eth0 nnn.nnn.nnn.n netmask 255.255.255.0 up

Maybe there will be some help for you on my ethernet page, you could also add an IP to the file I am sure you have which is /boot/cmdline.txt but I am not sure it will get ethernet started all by itself.

This page is written for ArchLinux, I am curious what file you do not have that needed to be edited?

http://sdjf.esmartdesign.com/raspberrypi/ethernet.html

I guess you guys do not have netctl? You do have systemd service files, don't you? I know it can be done with those to bring it up automatically but have not succeeded on my own setup with systemd for anything.
FORUM TIP: To view someone's posting history, sign in, click on their user name, then on "Search User's Posts." || Running ArchLinuxArm on Model 2B and 512MB Model B

doni49
Posts: 94
Joined: Wed Jan 23, 2013 4:59 pm

Re: Create Static IP Address for Ethernet in Raspian?

Sat Jun 01, 2013 2:19 am

Joe Schmoe wrote:I assume you've tried the obvious:

Code: Select all

ifconfig eth0 w.x.y.z
That may be obvious to you -- but how long have you been using this or any version/flavor of *nix? As of the time that I posted the question, I had been using *nix for all of about 60 minutes.
Joe Schmoe wrote:Did it work?
Since I was informed below that this will only work until the next reboot, I'm going to hold off on trying it.

doni49
Posts: 94
Joined: Wed Jan 23, 2013 4:59 pm

Re: Create Static IP Address for Ethernet in Raspian?

Sat Jun 01, 2013 2:23 am

klricks wrote:I set up my router for IP reservation to MAC address so that the router (DHCP) always gives my RPi the same IP address. Pretty easy to do and there is no configuration to do in the RPi.

Here is how I did this on my Linksys router others are similar:
http://64.13.91.137:86/Comp/RPi/DHCP.html

Does not matter if WIFI or wired it's the same setup.
I have a WRT54GS2 router and from what I've read, I can't do reserved IP address at the router. I've got a number of other devices on the network that use static IP -- but I manually entered their addresses on each device but made sure it was within a range that the router would allow without colliding with addresses assigned via DHCP.

doni49
Posts: 94
Joined: Wed Jan 23, 2013 4:59 pm

Re: Create Static IP Address for Ethernet in Raspian?

Sat Jun 01, 2013 2:29 am

sdjf wrote:This page is written for ArchLinux, I am curious what file you do not have that needed to be edited.
Here's link to the referenced post.

But here's the relevant snippet:
edit /etc/network.d/ethernet-eth0
When I went looking, I didn't even find the network.d folder.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Create Static IP Address for Ethernet in Raspian?

Sat Jun 01, 2013 2:32 am

Since I was informed below that this will only work until the next reboot, I'm going to hold off on trying it.
All methods "only work under the next reboot" - unless you make arrangements to run it as part of the boot process.

Once you've verified that the "ifconfig" command (given ear lier) works, then put it into the file /etc/rc.local - then it will run automatically on boot.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

doni49
Posts: 94
Joined: Wed Jan 23, 2013 4:59 pm

Re: Create Static IP Address for Ethernet in Raspian?

Sat Jun 01, 2013 2:38 am

ok thanks. That makes sense.

Part of my trouble is that I haven't found much in the way of what commands do what (and all there cryptic options). I've seen lots of tutorials about how to do specific projects -- but very little time is spent explaining what the different commands/options actually do.

I'm totally new to the *nix environment but I'm not afraid of a command line environment -- I got my start with computers way back on DOS 5.

I'll try that shortly.

doni49
Posts: 94
Joined: Wed Jan 23, 2013 4:59 pm

Re: Create Static IP Address for Ethernet in Raspian?

Sat Jun 01, 2013 2:47 am

Ok. I tried it exactly as you have it written (of course I used an appropriate IP address). But I got "Operation not permitted". I put SUDO in front of that and tried again -- it worked.

EDIT: I added this to the rc.local file (without sudo) and rebooted. It's now working on a Static IP. I greatly appreciate the help.

Is this rc.local the Linux equivalent of the DOS autoexec.bat file?

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

Re: Create Static IP Address for Ethernet in Raspian?

Sat Jun 01, 2013 5:35 am

Static addresses in Raspbian are configured in the file /etc/network/interfaces

The relevant lines for eth0 should be something like:

Code: Select all

auto eth0
iface eth0 inet static
    address w.x.y.z
    netmask 255.255.255.0
    gateway w.x.y.1       (assuming this is your gateway/router address)
and add the address of a DNS nameserver to /etc/resolv.conf

Code: Select all

nameserver 8.8.8.8
Interface eth0 will be given those parameters at boot time, and you can use ifup eth0 and ifdown eth0 to start/stop it afterwards.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Create Static IP Address for Ethernet in Raspian?

Sat Jun 01, 2013 10:03 am

Static addresses in Raspbian can be configured in the file /etc/network/interfaces
But need not be, as you can see.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Create Static IP Address for Ethernet in Raspian?

Sat Jun 01, 2013 10:05 am

Is this rc.local the Linux equivalent of the DOS autoexec.bat file?
More or less. Unix/Linux has a whole maze of twisty startup files (all different).

rc.local is just one way - and probably the easiest way - for you to put in something of your own that you want to have run as part of the booting process.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

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

Re: Create Static IP Address for Ethernet in Raspian?

Sat Jun 01, 2013 10:21 am

Joe Schmoe wrote:
Static addresses in Raspbian can be configured in the file /etc/network/interfaces
But need not be, as you can see.
No. But it is the recommended way of doing things in Debian/Raspbian - unless you have Network Manager (or something similar) installed.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Create Static IP Address for Ethernet in Raspian?

Sat Jun 01, 2013 10:38 am

Recommended by who?

Not me, as you can see.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

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

Re: Create Static IP Address for Ethernet in Raspian?

Sat Jun 01, 2013 11:04 am

Joe Schmoe wrote:Recommended by who?
http://wiki.debian.org/NetworkConfigura ... e_manually

plugwash
Forum Moderator
Forum Moderator
Posts: 3614
Joined: Wed Dec 28, 2011 11:45 pm

Re: Create Static IP Address for Ethernet in Raspian?

Sat Jun 01, 2013 10:50 pm

Joe Schmoe wrote:But need not be, as you can see.
Yes rather than changing the configuration file that specifies how the interface should be brought up you can let the standard startup scripts do the wrong thing and then change them after the fact from a custom startup script.

That doesn't make it a sane thing to do.

doni49
Posts: 94
Joined: Wed Jan 23, 2013 4:59 pm

Re: Create Static IP Address for Ethernet in Raspian?

Sun Jun 02, 2013 1:47 am

Well thanks everyone for the input. I ended up taking it OUT of the rc.local file and making the change in the network file.

I found that although doing it in rc.local DID allow me to assign a static ip (and it was accessible via the network), it wasn't able to access the internet.

By making the change in the network file, I was able to specify the address of the Gateway as well as the sub-net mask.

sdjf
Posts: 1395
Joined: Fri Mar 16, 2012 5:20 am
Location: California
Contact: Website

Re: Create Static IP Address for Ethernet in Raspian?

Sun Jun 02, 2013 4:52 pm

doni49 wrote:
Part of my trouble is that I haven't found much in the way of what commands do what (and all there cryptic options). I've seen lots of tutorials about how to do specific projects -- but very little time is spent explaining what the different commands/options actually do.
It takes a lot of time to explain every command and all it's options, so most folks do not bother unless they are told someone needs that amount of detail. And, even then, it has become so automatic that they do not realize that when they think they are giving a detailed explanation, it is nowhere detailed enough for someone new.

Unfortunately, going into total detail about every command that is needed to accomplish something is pretty intense work and makes for extremely big webpages and long answers, so most authors and forum members tend to avoid doing so.

I can recommend two things...one is to take the command you are interested in and put it into a google search along with tutorial and linux as keywords, and I think you should find more helpful pages.

I also have links to some old fashioned, down to earth webpages that explain basic linux and unix commands on the next page. The "Free Guides" links further down the page, do include links to TLDP project pages as well (The Linux Documentation Project), some are for networking, not sure which would be helpful for you. But for a command line refresher, I really like the FreeEngineers page linked to on page below.

http://sdjf.esmartdesign.com/new.html

What I find frustrating is a lot of tutorials for the Pi assume a specific distribution or setup, or rely heavily on GUI tools that not all of us can use.
FORUM TIP: To view someone's posting history, sign in, click on their user name, then on "Search User's Posts." || Running ArchLinuxArm on Model 2B and 512MB Model B

doni49
Posts: 94
Joined: Wed Jan 23, 2013 4:59 pm

Re: Create Static IP Address for Ethernet in Raspian?

Sun Jun 02, 2013 6:43 pm

sdjf wrote: It takes a lot of time to explain every command and all it's options, so most folks do not bother unless they are told someone needs that amount of detail. And, even then, it has become so automatic that they do not realize that when they think they are giving a detailed explanation, it is nowhere detailed enough for someone new.

Unfortunately, going into total detail about every command that is needed to accomplish something is pretty intense work and makes for extremely big webpages and long answers, so most authors and forum members tend to avoid doing so.
I totally understand that. It wasn't really meant to be a complaint that the authors aren't doing enough -- in fact, I appreciate the efforts that they DID put in to share their project documentation. I was just venting a little as I was becoming increasingly frustrated because I was finding myself needing to troubleshoot without a decent knowledge of how the commands work and what effect different options have.

Thanks for the link -- I'll give it a whirl.

Return to “Raspberry Pi OS”