Raspberry Pi help - How do I set a static IP?

Hello all,

I have been banging my head on a wall tonight because of this.

I cannot figure out how to set a static IP on openSUSE’s Raspberry Pi’s image

I added the following line to /etc/sysconfig/network/ifcfg-eth0

LLADDR=a1:2b:c3:4d:5e:f6

in an attempt to fix this.

Every time I reboot, I get a new randomly generated mac address.

Anyone have any suggestions?

If you type man ifcg in a command prompt, you will get the stuff below. Below it says that LLADDR Set an individual link layer address (MAC address).
**and that
** IPADDR[suffix] {IPv4|IPv6}[/PREFIXLEN]
IP address, either IPv4 or IPv6. You may add /<prefixlength> in both cases and omit NETMASK or PREFIXLEN. If you need more then one IP
address use this variable multiple times with different suffixes added. See section Multiple addresses below. If no address is configured
the interface will just be activated (UP).

**
So I think that you want to use the ‘variable’ IPADDR, not LLADDR.

a5’


NAME
       ifcfg - common elements of network interface configuration

SYNOPSIS
       /etc/sysconfig/network/ifcfg-*

FILENAMES AND EXTENSIONS
       Configuration filenames that contain the following blacklisted extensions, will be ignored by wicked:

       ~ .old .bak .orig .scpmbackup .rpmnew .rpmsave .rpmorig

VARIABLES
       The  following  is a list of variables that can be put in the configuration file, with an example in parentheses.  * marks the default.  For the
       meaning of suffix, see the section Multiple addresses.


       STARTMODE {manual*|auto|nfsroot|hotplug|off}
              Choose when the interface should be set up.
              manual
                     Interface will be set up if ifup is called manually
              auto
                     Interface will be set up as soon as it is available (and service network was started). This either happens at boot time when  net-
                     work  is  starting or via hotplug when a interface is added to the system (by adding a device or loading a driver). To be backward
                     compliant onboot, on and boot are aliases for auto.
              hotplug
                     Interface will be activated when it is available. Use instead of auto for devices which may be missed, such as bonding slaves, usb
                     or other plugable hardware.
              nfsroot
                     Nearly like auto, but interfaces with this startmode will be not shut down by default.  Use this mode when you use a root filesys-
                     tem via network or want to avoid interface shutdown. To force a nfsroot interface down, use  either  wicked ifdown --force device-
                     down <interface> or ifdown <interface> -o force.
              off
                     Will never be activated.

       Note:  Hotplugging is available only when wickedd-nanny is enabled.
              See wicked-config(5) for instructions how to enable it.
              Without nanny, an ifup call preforms a one-shot setup.



       BOOTPROTO {static*|dhcp|dhcp4|dhcp6|autoip|dhcp+autoip|6to4|none}
              Setup protocol. If this variable is empty or missing, it defaults to static.
              static
                     A  fixed  addresses specified in IPADDR and related variables and static routing as defined in routes and ifroute-<interface name>
                     files is configured. This option does not prevent from getting dynamic IPv6  addresses  and  routes  from  Router  Advertisements,
                     though.
              dhcp4 dhcp6 dhcp
                     A  DHCPv4,  DHCPv6  or  both clients are started to configure the interface. The setup is considered successful, when at least one
                     dhcp client configures the interface. Additionally to the dhcp client configuration, fixed addresses and routes may also be speci-
                     fied.
                     Note:
                     Static  routes take precedence over routes provides by dhcp or other leases, that is, a DHCPv4 route with same metrics as a static
                     one will be skipped.  DHCPv6 does not support routing options, an IPv6 Router Advertisement (RA) is applying them.
              autoip dhcp+autoip
                     may be used for a IPv4 zeroconf setup or as fall back to autoip if dhcp fails.
              6to4
                     to set up IPv6 tunnel interfaces running in the "6to4" mode.
                     See also ifcfg-tunnel(5) manual page.
              none
                     For bonding slaves, to skip the link-layer (MTU, MAC address) setup and IP configuration of the interface  in  ifup.  The  bonding
    script handles the link layer settings itself at enslave time. See also ifcfg-bonding(5) man page.  Note:  Do not use to just skip
                     the IP setup -- use BOOTPROTO="static" without any addresses in the IPADDR variables (or routes) instead.


       IPADDR[suffix] {IPv4|IPv6}[/PREFIXLEN]
              IP address, either IPv4 or IPv6. You may add /<prefixlength> in both cases and omit NETMASK or PREFIXLEN.  If you need more then  one  IP
              address use this variable multiple times with different suffixes added. See section Multiple addresses below. If no address is configured
              the interface will just be activated (UP).

       PREFIXLEN[suffix]
              Number of bits in IPADDR that form the network address. Alternatively add a prefix-length to IPADDR or use NETMASK.   PREFIXLEN  is  pre-
              ferred over NETMASK.  but highest priority has a prefix-length added to the IP address in the variable IPADDR.

       NETMASK[suffix]
              Network mask. Alternatively add a prefix-length to IPADDR or use PREFIXLEN.  This variable is ignored if a prefix-length is specified.

       BROADCAST[suffix]
              Network broadcast. If you omit the broadcast address, it will be calculated from netmask or prefix-length. You can affect the calculation
              with the variable DEFAULT_BROADCAST in /etc/sysconfig/network/config.  See the description there.

       REMOTE_IPADDR[suffix]
              The remote IP address of a point to point  connection

       LABEL[suffix]
              Each address may be tagged with a label  string.   In  order  to preserve compatibility  with Linux-2.0 net  aliases,  this  string  must
              coincide  with  the  name  of the device or  must  be  prefixed with the device name followed by colon.  This may be useful with Multiple
              addresses (see below).

       SCOPE[suffix]
              The scope of the area where this address is valid.  The available scopes are listed in file  /etc/iproute2/rt_scopes.   Predefined  scope
              values are:
                      global - the address is globally valid.

                      site - (IPv6 only) the address is site local, i.e. it is valid inside this site.

                      link - the address is link local, i.e. it is valid only on this device.

                      host - the address is valid only inside this host.

       MTU    Set the maximum transfer unit (MTU) for this interface.

       IP_OPTIONS[suffix]
              Any other option you may want to give to the ip add add ...  command. This string is appended to the command.

       LLADDR Set an individual link layer address (MAC address).

       LINK_OPTIONS
              Here you may add any option valid with ip link set up ...

       INTERFACETYPE
              In case ifup cannot determine the interface type properly, you may specify the correct type in this variable to override the behavior and
              force ifup to handle the interface differently than it detected from system or config.  Please always  open  a  bug  report  when  it  is
              required to set the type.

       ETHTOOL_OPTIONS  suffix ]
              If  this  variable is not empty, wicked will set these options on an ethernet type device.  See the ethtool (8) manual page for available
              options.  If the option string starts with a '-' (e.g. '-K iface rx on'), then the second word in the string will be  replaced  with  the
              current  interface  name.   Otherwise  (e.g. 'autoneg off speed 10') ifup prepends '-s <interface>'.  The optional variable suffix can be
              used to apply every setting separately, e.g.:

                ETHTOOL_OPTIONS='autoneg off speed 10'
                ETHTOOL_OPTIONS_gro='-K iface gro off'
                ETHTOOL_OPTIONS_lro='-K iface lro off'
              The NIC driver may reject settings as not supported (e.g. '-K iface lro off') or also when the link is not up.

       TUNNEL, TUNNEL_*
              Using this variable you may set up different tunnels. See ifcfg-tunnel (5) manual page.

       ETHERDEVICE
              Needed only for virtual LANs (802.1q). It contains the real interface to use for the vlan interface. See ifcfg-vlan (5) manual page.

       BONDING_MASTER, BONDING_SLAVE_*, BONDING_OPTS, BONDING_MODULE_OPTS
              These are used to set up interface bonding. See ifcfg-bonding (5) manual page.

       IPOIB_MODE
              is used to set the infiniband transport mode of an IB device to one of "connected" (CM - Connected Mode) or "datagram" (UD  -  Unreliable
              Datagram).

       IPOIB_UMCAST
              is used to enable/disable user-multicast for an IB device by setting to "allowed" or "disallowed".


GENERAL VARIABLES
       There are some general settings in the file /etc/sysconfig/network/config and /etc/sysconfig/network/dhcp.  See the ifup (8) manual page.


Multiple addresses
       You  can extend the variable name IPADDR by any string you like. For example IPADDR_1, IPADDR-FOO or IPADDRxxx.  Use these variables for your IP
       addresses.  If you need some additional parameters for these addresses, then just add the same extension to  these  variable  names:  BROADCAST,
       NETMASK, PREFIXLEN, REMOTE_IPADDR, LABEL, SCOPE, IP_OPTIONS.

       Example:
          IPADDR_AAA=1.2.3.4
          NETMASK_AAA=255.0.0.0
          BROADCAST_AAA=1.2.3.55
          IPADDR_BBB=10.10.2.3/16
          LABEL_BBB=BBB
          and so on ...

COPYRIGHT
       Copyright (C) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.

BUGS
       Please report bugs at <https://bugzilla.novell.com/index.cgi>

AUTHOR
       Michal Ludvig -- tunneling
       Pawel Wieczorkiewicz -- wicked

SEE ALSO
       ifcfg-dhcp(5), ifcfg-bonding(5), ifcfg-tunnel(5), ifcfg-vlan(5), ifcfg-wireless(5), wicked(8).


             
            

Thank you for the reply!

Sorry, however, for the confusion about this.

I did mean set a static MAC address.

The thing is, I use DHCP at home, and I set some IP addresses to be reserved on my home network through DHCP.

To reserve an IP, I have to use a mac addresses.

So, I see how the wording of my previous question was a bit off.

Setting the IP statically on my device could generate problems since I can’t reserve that IP address at home without a mac address. If I don’t reserve, another device might have that IP assigned leading to some devices colliding for IP addresses. i.e: One device assigned the IP address, the other that’s hardcoded to want that device.

I appreciate that but I only found that…Don’t have any other ideas.

Did find this also though

http://www.faqs.org/docs/securing/chap9sec90.html
https://gitorious.org/wicked/wicked/source/c748b248ed121a5f1b73ed8d233328af239774cb:Documentation/WhyWicked.txt

I think it depends on the network management tool

Wicked looks to be feature rich if you are doing something fancy.

a5’

Ahhh, ok. I do know that it is running the wicked service, so that might be a way to solve this.

wanted to see if someone had run into this problem on here.

I think that the rotating MAC address is something that Raspberry Pi does and is dealt with in one way with Debian based Raspberry Pi images. The way to fix it on there is by adding a line to a file or files that exists on Raspian, I believe /etc/cmdline.txt and/or /etc/network/interfaces

I’ll try to set the MAC address to static through wicked at night, or whenever I have some time.

I guess another way to fix this is to find WHICH service is setting the MAC address to something random every time.

In any case, thanks for the help and suggestions! I’ll post if I find a solution or work around.

Great! Good Luck.

a5’

You could set a static IP for your device if your router or whatever DHCP server you may have allows setting the DHCP address pool which they serve (most home routers do). So you could set your router to dynamically serve addresses outside of your static range. For example, if your router has an internal LAN IP address of 192.168.0.1 and a subnet mask of 255.255.255.0, you could make it serve DHCP clients addresses starting from 192.168.0.50 and have the .2-.49 addresses free for your own static-assignment purposes.

Hahaha! you’re right! Hadn’t thought of that! :slight_smile:

Was trying to do some ifconfig work around to change the MAC. but I’m headless right now, as my screen doesn’t have an HDMI input. The ifconfig wasn’t working.

I think you’re suggestion will work. Although I might or might not lose my reservations for the other devices. We’ll see.

I’ll post in a moment. Thanks!

Unfortunately that didn’t work.

I set that up with a static IP, and it wasn’t taking.

What I mean is, I think something else is controlling the networking. I changed IPADDR to something static in ifcfg-eth0. I think DHCP would change it to something , and some other service would want to change it to the static address that I’d like to set it to.

I was able to connect to the device on 2 different IP addresses. I have a screenshot, but I don’t think I can post attachments.

Anyway, I’m giving up for a couple of days until I can free up some more time. I sent an email to the mailing list. Hoping to get back at some point hopefully.

Thanks for the suggestions!