Setting a Static IP Address Using the Kernel Command Line

Question: How do I set a static IP address using the kernel command line?

Answer:

Use the “ip=” parameter on the command line. This parameter tells the kernel how to configure the IP addresses of devices and how to set up the IP routing table. The command has the form:

ip=<client-ip>:<srv-ip>:<gw-ip>:<netmask>:<host>:<device>:<autoconf>

where:

  • <client-ip> is the IP address of the client.
  • <srv-ip> is the IP address of the NFS server. If this entry is blank, the address of the server which answered the BOOTP (or RARP) request is used.
  • <gw-ip> is the IP address of a gateway if the server is on a different subnet. If this entry is empty, the server is assumed to be on a local network, unless a value has been received by BOOTP.
  • <netmask> is the netmask for local network interface. If this is empty, the netmask is derived from the client IP address or from the BOOTP reply.
  • <host> is the name of the client. If empty, the client IP address is used in ASCII notation, or the value received by BOOTP.
  • <device> is the name of network device to use for RARP and BOOTP requests. If this entry is empty, all devices are used, and the first device responding is configured. If you have only one device, you can safely leave this blank.
  • <autoconf> is the method to use for autoconfiguration. If this is the only parameter (without all the ':' characters before), and its value is not off, then autoconfiguration is used.
    • If this value is either rarp or bootp, the specified protocol is used.
    • If the value is both, or is empty, both protocols are used if they have been enabled during kernel configuration.
    • If the value is off, no autoconfiguration will be used.

Example:

  • The client (target board’s) IP address is 192.168.1.90.
  • The <server-ip> value is empty, so the NFS server’s (host’s) IP address will be the address of the server which answers the BOOTP request.
  • The IP address of the NFS server’s subnet gateway is 192.168.2.1.
  • The netmask of the local network is 255.255.255.0.
  • The name of the client (the target board) is at9261.
  • The Ethernet device eth0 will be automatically configured using BOOTP.

NFS:

If you are mounting your RFS over NFS you also need to set the nfsroot parameter on the kernel command line:

nfsroot=<server-ip>:<root-dir>,<nfs-options>

where:

  • <server-ip> is the IP address of the NFS server.
  • <rootdir> is the exported directory on the server.
  • <nfs-options> are the mount options.

Example:

nfsroot=192.168.1.3:/opt/exports/at91sam9263-dev/rfs,rw

For more information, refer to the nfsroot.txt file in the Documentation subdirectory of your kernel. It discusses mounting the root filesystem via NFS in more detail.