Amazon holiday deals See deals →ad

Mets Minor League Blog

Music theory, instruments and musicians

Mets Minor League Blog

Music theory, instruments and musicians

Linux Add IP Address: Temporary and Persistent Setup

To add an IP address on Linux temporarily, run sudo ip address add 192.0.2.10/24 dev eth0, replacing the example address, prefix, and interface with values for your network. The change takes effect immediately but usually disappears when the interface or system restarts; for a lasting setup, configure the network manager that controls the interface.

What the ip address command does

The ip utility is the standard command-line tool for inspecting and changing Linux network settings. The ip address add operation assigns an address to a network interface in the running system. It does not, by itself, create a route to every network, set a default gateway, configure DNS, or make the address permanent.

In the example, 192.0.2.10 is an example IPv4 address, /24 is its network prefix length, and eth0 is the interface name. The address range beginning 192.0.2 is reserved for documentation, so use an address actually allocated to your network rather than copying the example. A typical real interface might be named enp1s0, ens33, or wlan0.

You need administrative privileges to change interface addresses, which is why the command uses sudo. On distributions where you are already logged in as root, omit it. The command syntax is:

sudo ip address add ADDRESS/PREFIX dev INTERFACE

This adds an address without removing any other addresses already assigned to that interface. That makes it useful for adding a secondary address, but it also means the command may not replace an incorrect address you meant to change.

Find the interface and choose the right prefix

Before changing anything, identify the interface connected to the network you intend to configure. Run ip -brief link to see interface names and link state, or ip -brief address to see interfaces alongside their assigned addresses. For more detail, use ip address show. A name such as lo refers to the loopback interface; it is not normally the interface for a physical or wireless network.

The prefix is essential. It tells Linux how many leading bits of an address identify the local network. For example, /24 is equivalent to the familiar IPv4 subnet mask 255.255.255.0. Do not assume every network uses /24: an administrator, router configuration, or network plan should provide the correct prefix. A wrong prefix can make Linux treat nearby devices as remote, or treat remote addresses as directly connected.

Also confirm that the address is available and belongs to the network. Reusing another device’s address can cause intermittent connectivity or an IP conflict. On a managed office, school, cloud, or hosting network, use the address and prefix supplied by the network administrator or provider. Private addresses such as 192.168.x.x are common on local networks, but being private does not make an arbitrary address safe to assign.

Add an address step by step

  1. Check the interface name and current settings with ip -brief address.
  2. Confirm the intended address and prefix, and make sure no other device is using that address.
  3. Run the add command with the correct interface. For example: sudo ip address add 192.0.2.10/24 dev enp1s0.
  4. Check the result with ip address show dev enp1s0 or ip -brief address.
  5. Test connectivity to an appropriate local or remote destination, and check routes if traffic does not go where expected.

If the interface is administratively down, the address can be present without the link being usable. You can bring it up with sudo ip link set dev enp1s0 up, but do this only if appropriate for the device and network manager. A cable unplugged from a wired port or a disconnected Wi-Fi network is a separate link problem: assigning an IP address does not establish a physical or wireless connection.

Check routes, gateway, and connectivity

Linux generally creates a connected route for the subnet implied by an assigned address and prefix. That route lets the system reach addresses it considers to be on the same network, subject to link and firewall conditions. It does not automatically provide a default route to other networks. Inspect the routing table with ip route; IPv6 routes can be viewed with ip -6 route.

If you need a default gateway and one has not been configured by DHCP or a network manager, a temporary IPv4 default route can be added with sudo ip route add default via 192.0.2.1 dev enp1s0. Replace the example gateway with the one specified for your network. Do not add a second competing default route casually: multiple routes can produce unexpected traffic paths, and route selection depends on route metrics and other settings.

DNS is another separate setting. A machine can have a valid address and route but still fail to open websites by name if DNS is missing or incorrect. Test an IP destination and a hostname separately to narrow down the cause. On systems managed by NetworkManager, systemd-resolved, or another service, configure DNS through that service instead of assuming that editing a resolver file will persist.

Make the address persistent

The ip address add command changes the active kernel network configuration; it is not a universal way to save settings across reboot. Linux distributions use different configuration systems, and a network manager may replace manual changes when it renews a DHCP lease, reconnects, or activates a profile. For a persistent address, edit the configuration owned by the system managing that interface.

On a system using NetworkManager, first find the connection profile with nmcli connection show. A manual IPv4 configuration can be set on a profile with a command such as:

sudo nmcli connection modify 'Wired connection 1' ipv4.method manual ipv4.addresses 192.0.2.10/24 ipv4.gateway 192.0.2.1 ipv4.dns 192.0.2.53

Use the actual profile name and network values. Activate the profile with sudo nmcli connection up 'Wired connection 1' when it is safe to do so. Bringing a profile up can interrupt the connection, especially over SSH. If you want to add an address to an existing profile rather than replace its address list, NetworkManager supports the + property modifier, for example +ipv4.addresses; check the current profile first so you do not unintentionally discard working settings.

Ubuntu installations using Netplan store network configuration in YAML files under /etc/netplan/. A static-address configuration commonly specifies the interface, disables DHCP for that address family, and lists the address with its prefix. A default route and DNS nameservers may also be needed, depending on the network. Netplan syntax and available options can vary with the renderer and software version, so inspect the existing file and use the system’s documented configuration rather than replacing it blindly. sudo netplan try can help test changes with a chance to revert if connectivity is lost; review the prompt and timeout.

Other systems may use systemd-networkd, distribution-specific scripts, or a server management tool. Check which service owns the interface before editing files. Two services trying to manage the same connection can repeatedly overwrite one another’s settings. The important distinction is that ip is useful for immediate changes and diagnosis, while the persistent configuration belongs to the active network manager.

IPv6 addresses

The same tool can add IPv6 addresses. Its syntax is similar, but use an IPv6 address and the correct prefix length, such as sudo ip -6 address add 2001:db8:1::10/64 dev enp1s0. The 2001:db8::/32 block is reserved for documentation, not ordinary public connectivity. A real IPv6 address and prefix must come from the network or provider.

IPv6 networks commonly use a /64 on a local subnet, but do not assume that is appropriate in every design. IPv6 may also be configured automatically through router advertisements or a network manager. Adding a static address does not ensure that the machine has a usable IPv6 route, gateway behavior, or DNS. Check with ip -6 address show and ip -6 route, and avoid disabling automatic configuration unless you understand how the network supplies IPv6 settings.

Common problems and safe removal

  • Device not found: The interface name may be wrong. Recheck ip link; names are often not simply eth0.
  • Operation not permitted: Run the command with sudo or from an authorized root shell.
  • Address already exists: It may already be configured. Inspect the interface before adding it again; duplicate entries are not a way to repair a prefix or route.
  • Address appears, but traffic fails: Check link state, prefix, route, firewall, gateway, and DNS separately. An address alone does not prove end-to-end connectivity.
  • Setting disappears: A reboot or network manager likely reapplied its configuration. Save the change in the manager’s persistent profile.
  • Connection drops after a change: A conflicting address, incorrect prefix, route, or profile activation may have interrupted access. Use a console or out-of-band access for risky remote changes.

To remove a temporary address, specify the same address, prefix, and interface with del: sudo ip address del 192.0.2.10/24 dev enp1s0. Removing it from the live interface does not necessarily remove it from a persistent profile, so it may return when that profile is reactivated. Conversely, changing only the profile may leave the currently active address until the connection is renewed.

Avoid using a broad flush command as a shortcut when connected remotely. Flushing addresses can remove settings needed for the current session and cut off access. Before experimenting on a server, keep a recovery route such as a local console, provider console, or scheduled rollback, and record the original configuration. On a desktop, make sure you know how to restore the active connection before applying a new profile.

Frequently Asked Questions

How do I add a second IP address to a Linux interface?
Run sudo ip address add ADDRESS/PREFIX dev INTERFACE with the additional address and correct prefix. The command normally leaves existing addresses in place. For the address to survive reconnects or reboots, add it to the interface’s persistent network-manager profile as well.

Does ip address add survive a reboot?
No, it normally changes only the active kernel configuration. A network service may also remove or replace it before reboot. Configure the address in the system’s active network manager, such as NetworkManager or Netplan, for a persistent setup.

How do I change an IP address instead of adding one?
Inspect the existing address first, then remove the old address with ip address del and add the new one, or update the persistent connection profile and reactivate it. Changing addresses remotely can disconnect you, so confirm the new route and keep a recovery method available.

Can I add an IP address without a gateway?
Yes. A host can have an address and communicate with devices on its directly connected subnet without a default gateway. It generally needs a suitable route or gateway to reach destinations outside that subnet; the exact routing depends on the network.

How do I add an IP address in Linux for IPv6?
Use sudo ip -6 address add ADDRESS/PREFIX dev INTERFACE, supplying an IPv6 address and the prefix assigned to your network. Check IPv6 routes separately, and configure the address persistently through the service managing the interface if needed.

Linux Add IP Address: Temporary and Persistent Setup
Scroll to top