User Tools

Site Tools


eduardo:linux:ip

IP Address

Temporary

  • Use ifconfig command:
# ifconfig eth0 192.168.1.5 netmask 255.255.255.0 up

Permanent

  • Find the configuration file corresponding to the NIC for which you want to set a static IP and edit it.
# cd /etc/sysconfig/networking/devices
# vi ifcfg-eth0
  • Now set the parameters below according to your settings
DEVICE=eth0
BOOTPROTO=none
HWADDR=00:0C:29:DE:94:8B
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
NETMASK=255.255.255.0
IPADDR=192.168.0.100
GATEWAY=192.168.0.1
  • To set the nameservers, change directory to /etc and edit resolv.conf.
# cd /etc
# vi resolv.conf
  • The file format should be like this:
search your-dns-search-path
nameserver dns1-ip-address
nameserver dns2-ip-address
nameserver dns3-ip-address
  • Now save the configuration file and exit the text editor. To apply changes, we need to bring the network interface down and back up.
# ifdown eth0
# ifup eth0

Redhat 7.X

ifconfig

The minimal install does not include ifconfig. To install ifconfig run the following:

yum install net-tools

EnsXXX

In Redhat 7.X, the interface naming convention has changed from ethX to EnsXXX. To restore the default behavior, do the following:

  1. Edit /etc/default/grub to add the lines to the kernel paramaters:
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
  1. grub2-mkconfig -o /boot/grub2/grub.cfg
  2. Rename /etc/sysconfig/network-scripts/ifcfg-enXXX to ifcfg-eth0
  3. Set Name=eth0 and Device=eth0 in /etc/sysconfig/network-scripts/ifcfg-eth0
  4. reboot
eduardo/linux/ip.txt · Last modified: 2024/02/23 08:20 by 127.0.0.1