Static IP Address: Difference between revisions

From Variscite Wiki
No edit summary
No edit summary
Line 5: Line 5:
= Using /etc/network/interfaces =
= Using /etc/network/interfaces =


Edit /etc/network/interfaces and add configuration sections for network interfaces. The example below configures eth0
Edit /etc/network/interfaces to add configuration sections for network interfaces. The example below configures eth0


<pre>
<pre>
auto eth0
auto eth0
     iface eth0 inet static
     iface eth0 inet static
     address 192.0.2.7
     address 192.168.1.100
     netmask 255.255.255.0
     netmask 255.255.255.0
     gateway 192.0.2.254
     gateway 192.168.1.254
    dns-nameservers 66.212.63.228 66.212.48.10 
</pre>
</pre>


= Configure connman interface blacklist =
Please note that /etc/network/interfaces is a configuration file of ifup/ifdown tools that do the actual interface setup work. In the SystemV init setup they are invoked by /etc/init.d/networking script during boot. If you're using systemd instead of SystemV init, /etc/init.d/networking is not available and you should create your own systemd service file that invokes "ifup -a" on boot.
= Connman interaction with /etc/network/interfaces =


The default Yocto network manager is connman. It is a service to manage network connections in embedded devices. Connman may override the settings in /etc/network/interfaces unless configured to blacklist certain interfaces. For example, after configuring eth0 and eth1 in /etc/network/interfaces, create /etc/connman/main.conf and add the following:
The default Yocto network manager is connman. It is a service to manage network connections in embedded devices. Connman will override the settings in /etc/network/interfaces unless configured to blacklist certain interfaces. For example, after configuring eth0 and eth1 in /etc/network/interfaces, you should create /etc/connman/main.conf and add the following:


<pre>
<pre>
Line 24: Line 27:
</pre>
</pre>


= Configure static IP using connman =
= Configure static IP using connmanctl =
Instead of using /etc/network/interfaces one can use connman command line interface to configure static IP. To create initial configuration the relevant interface should be connected to the network.
Instead of using /etc/network/interfaces one can use connmanctl tool to configure static IP. To create initial configuration the relevant interface should be connected to the network.


To get the list of connections run
To get the list of connections run
Line 42: Line 45:


  # connmanctl <service> --ipv4 manual <ip address> <netmask> <gateway>
  # connmanctl <service> --ipv4 manual <ip address> <netmask> <gateway>
# connmanctl config <service> --nameservers <dns-addr>


For example:
For example:
   # connmanctl ethernet_0eb31468dcc9_cable --ipv4 manual 192.0.2.7 255.255.255.0 192.0.2.254
   # connmanctl ethernet_0eb31468dcc9_cable --ipv4 manual 192.168.1.100 255.255.255.0 192.168.1.254
  # connmanctl config ethernet_0eb31468dcc9_cable --nameservers 66.212.63.228 66.212.48.10
 
The configuration will be saved in /var/lib/connman/ethernet_0eb31468dcc9_cable/settings.
 
The downside of this method is the use of non-constant parameters (e.g. MAC address) to identify the connection, which makes it impossible to incorporate the configuration into Yocto image and use it on multiple devices.
 
= NetworkManager interaction with /etc/network/interfaces =
 
NetworkMananager is an alternative to connman. Both cannot coexist in the same Yocto image, so the image should be rebuilt after enabling NetworkManager. Interfaces configured via /etc/network/interfaces are automatically ignored by NetworkMananager, so nothing special should be done.
 
= Configure static IP using nmcli =
 
The NetworkManager command line tool, nmcli, can also be used create static IP configuration. In the example below a permanent static configuration is created for interface eth0.
 
<pre>
# nmcli con add type ethernet ifname eth0 name static-eth0 ip4 192.168.1.100 gw4 192.168.1.254
# nmcli con mod static-eth0 ipv4.dns "66.212.63.228,66.212.48.10"
</pre>
 
The configuration will be saved in /etc/NetworkManager/system-connections/static-eth0. Once generated it can be incorporated into Yocto image and used on multiple devices.

Revision as of 14:51, 14 October 2018

Configuring Static IP Addresses

It is sometimes desirable to provide static IP configuration for network interface instead of relying on DHCP.

Using /etc/network/interfaces

Edit /etc/network/interfaces to add configuration sections for network interfaces. The example below configures eth0

auto eth0
    iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.254
    dns-nameservers 66.212.63.228 66.212.48.10  

Please note that /etc/network/interfaces is a configuration file of ifup/ifdown tools that do the actual interface setup work. In the SystemV init setup they are invoked by /etc/init.d/networking script during boot. If you're using systemd instead of SystemV init, /etc/init.d/networking is not available and you should create your own systemd service file that invokes "ifup -a" on boot.

Connman interaction with /etc/network/interfaces

The default Yocto network manager is connman. It is a service to manage network connections in embedded devices. Connman will override the settings in /etc/network/interfaces unless configured to blacklist certain interfaces. For example, after configuring eth0 and eth1 in /etc/network/interfaces, you should create /etc/connman/main.conf and add the following:

[General]
NetworkInterfaceBlacklist=eth0,eth1

Configure static IP using connmanctl

Instead of using /etc/network/interfaces one can use connmanctl tool to configure static IP. To create initial configuration the relevant interface should be connected to the network.

To get the list of connections run

# connmanctl services

For example:

root@imx7-var-som:~# connmanctl services
*AO Wired                ethernet_0eb31468dcc9_cable

Wired Ethernet connection would be shown as ethernet_<mac_address>_cable.

To configure static IP, run

# connmanctl <service> --ipv4 manual <ip address> <netmask> <gateway>
# connmanctl config <service> --nameservers <dns-addr> 

For example:

 # connmanctl ethernet_0eb31468dcc9_cable --ipv4 manual 192.168.1.100 255.255.255.0 192.168.1.254
 # connmanctl config ethernet_0eb31468dcc9_cable --nameservers 66.212.63.228 66.212.48.10 

The configuration will be saved in /var/lib/connman/ethernet_0eb31468dcc9_cable/settings.

The downside of this method is the use of non-constant parameters (e.g. MAC address) to identify the connection, which makes it impossible to incorporate the configuration into Yocto image and use it on multiple devices.

NetworkManager interaction with /etc/network/interfaces

NetworkMananager is an alternative to connman. Both cannot coexist in the same Yocto image, so the image should be rebuilt after enabling NetworkManager. Interfaces configured via /etc/network/interfaces are automatically ignored by NetworkMananager, so nothing special should be done.

Configure static IP using nmcli

The NetworkManager command line tool, nmcli, can also be used create static IP configuration. In the example below a permanent static configuration is created for interface eth0.

# nmcli con add type ethernet ifname eth0 name static-eth0 ip4 192.168.1.100 gw4 192.168.1.254
# nmcli con mod static-eth0 ipv4.dns "66.212.63.228,66.212.48.10"

The configuration will be saved in /etc/NetworkManager/system-connections/static-eth0. Once generated it can be incorporated into Yocto image and used on multiple devices.