How do I add a second private IP address to a network interface that's attached to my EC2 instance that's running RHEL?

2 minutos de lectura
0

I want to add a second IP address to my elastic network interface that's attached to my Amazon Elastic Compute Cloud (Amazon EC2) instance that's running Red Hat Enterprise Linux (RHEL). I want the secondary IP address to persist during bootup.

Short description

To make the second Elastic IP address persist during the reboot, you must create an alias interface configuration file, for example /etc/sysconfig/network-scripts/ifcfg-eth0:1. The ifcfg-if-name:alias-value naming scheme is used to bind multiple addresses to a single interface in the alias interface configuration files, for example ifcfg-eth0:1.

Resolution

To create the alias interface configuration file for the secondary IP address and bind the IP address to eth0of, complete the following steps:

  1. Attach a secondary IPv4 address to the network interface.

  2. Use SSH to connect to the Linux instance.

  3. To check if an alias configuration file already exists, run the following command:

    "ls /etc/sysconfig/network-scripts/ifcfg-eth0\:*" 
  4. If the alias configuration file doesn't exist, then run the following command to create one:

    sudo cat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth0:1
    DEVICE=eth0:1
    TYPE=Ethernet
    BOOTPROTO=static
    IPADDR=192.168.1.10
    NETMASK=255.255.255.0
    ONBOOT=yes
    USERCTL=yes
    NM_CONTROLLED=no
    EOF
  5. To activate the alias on the network interface based on the interface definitions in the alias configuration file, run the following command:

    sudo ifup eth0:1

    The following is an example output:

    Determining if ip address 192.168.1.10 is already in use for device eth0...
  6. To confirm that the IP address is bound to the network interface, run the following command:

    ip a

    The following is an example output:

    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
         link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
        inet6 ::1/128 scope host
            valid_lft forever preferred_lft forever
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc pfifo_fast state UP qlen 1000
        link/ether 0a:ff:f2:5a:69:e7 brd ff:ff:ff:ff:ff:ff
        inet 172.31.18.200/20 brd 192.168.1.10 scope global eth0
        inet 192.168.1.10/24 brd 10.0.1.255 scope global eth0:1
        inet6 fe80::8ff:f2ff:fe5a:69e7/64 scope link
            valid_lft forever preferred_lft forever
  7. To confirm that the IP address is assigned, reboot the instance.

OFICIAL DE AWS
OFICIAL DE AWSActualizada hace 2 meses