Technology Encyclopedia Home >How to set a static IP on Alpine Linux?

How to set a static IP on Alpine Linux?

To set a static IP address on Alpine Linux, you typically modify the network configuration files. Here’s how you can do it:

  1. Locate the Network Configuration File: The network configuration for Alpine Linux is usually found in /etc/network/interfaces or /etc/network/interfaces.d/.

  2. Edit the Configuration File: Use a text editor like vi or nano to edit the configuration file. For example, if you are using vi, you would run:

    vi /etc/network/interfaces
    
  3. Add Static IP Configuration: Add or modify the configuration to set a static IP. Here’s an example configuration for an interface named eth0:

    auto eth0
    iface eth0 inet static
        address 192.168.1.100
        netmask 255.255.255.0
        gateway 192.168.1.1
        dns-nameservers 8.8.8.8 8.8.4.4
    

    In this example:

    • address is the static IP address you want to assign.
    • netmask defines the subnet mask.
    • gateway is the IP address of the default gateway.
    • dns-nameservers specifies the DNS servers to use.
  4. Restart the Network Service: After saving the changes, restart the network service to apply the new configuration:

    service networking restart
    

    Or, if you are using dhclient:

    dhclient -r eth0 && dhclient eth0
    
  5. Verify the Configuration: Check if the static IP has been applied successfully by running:

    ip addr show eth0
    

This should display the interface with the static IP address you configured.

Example:
If you want to set a static IP of 192.168.1.100 on eth0, your configuration would look like this:

auto eth0
iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 8.8.8.8 8.8.4.4

If you are working in a cloud environment like Tencent Cloud, you might also consider using their services for managing network configurations, such as setting up Virtual Private Cloud (VPC) and configuring subnets and route tables to manage IP addresses more dynamically and securely.