How To Set DHCP/Static IP Address in Centos/RHEL/Fedora & Debian/Ubuntu/Kubuntu/MEPIS Set DHCP/Static IP Address

Basically the two main types of distros are Debian and RHEL/Centos based.  I'm just going to give a quick overview of how the configuration of IP interfaces works in Debian/Centos based distros.

*Just one thing to remember, when setting IPs statically you have to manually specify a DNS server in /etc/resolv.conf (since DHCP is what normally does it automatically)

Debian/Ubuntu/Kubuntu/MEPIS

The IP (DHCP & Static) configuration is done from the following file: /etc/network/interfaces

Here is how the default DHCP configuration looks:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
auto eth0
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp

Here is an example of setting it statically:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
auto eth0
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet static
        address 192.168.1.147
        netmask 255.255.255.0
        gateway 192.168.1.1

 

How to Add Multiple IPs in Debian/Ubuntu

auto eth0:0

iface eth0:0 inet static

    address  192.168.1.148

    netmask 255.255.255.0

    gateway 192.168.1.1


auto eth0:1

iface eth0:1 inet static

    address  192.168.1.149

    netmask 255.255.255.0

    gateway 192.168.1.1

 

*Just one thing to remember, when setting IPs statically you have to manually specify a DNS server in /etc/resolv.conf (since DHCP is what normally does it automatically)

 

 


 

Centos/RHEL/Fedora/Mandriva

The IP (DHCP & Static) configuration is done from the following file : /etc/sysconfig/network-scripts/ifcfg-eth0

*Note the "eth0" at the end, each device has it's own entry within the network-scripts directory.

Here is how the default DHCP configuration looks:

# Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=5A:G1:29:4A:1C:76
ONBOOT=yes

Here is an example of setting it statically:

DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.1.245
GATEWAY=192.168.1.1
NETMASK=255.255.255.0
ONBOOT=YES

*Just one thing to remember, when setting IPs statically you have to manually specify a DNS server in /etc/resolv.conf (since DHCP is what normally does it automatically)


Tags:

dhcp, static, ip, centos, rhel, fedora, debian, ubuntu, kubuntu, mepis, addressbasically, distros, overview, configuration, interfaces, ips, statically, manually, specify, dns, server, etc, resolv, conf, automatically, default, describes, activate, loopback, interface, auto, eth, iface, inet, primary, hotplug, netmask, gateway, multiple, mandriva, sysconfig, scripts, ifcfg, quot, entry, directory, realtek, semiconductor, ltd, rtl, pci, gigabit, ethernet, controller, bootproto, hwaddr, onboot, ipaddr,

Latest Articles

  • Linux Ubuntu Cannot Print Large Images
  • Cannot Print PDF Solution and Howto Resize
  • Linux Console Login Screen TTY Change Message
  • Apache Cannot Start Listening Already on 0.0.0.0
  • MySQL Bash Query to pipe input directly without using heredoc trick
  • CentOS 6 and 7 / RHEL Persistent DHCP Solution
  • Debian Ubuntu Mint rc-local service startup error solution rc-local.service: Failed at step EXEC spawning /etc/rc.local: Exec format error
  • MySQL Cheatsheet Guide and Tutorial
  • bash script kill whois or other command that is running for too long
  • Linux tftp listens on all interfaces and IPs by DEFAULT Security Risk Hole Solution
  • python import docx error
  • Cisco Unified Communications Manager Express Cheatsheet CUCME CME
  • Linux Ubuntu Debian Missing privilege separation directory: /var/run/sshd
  • bash how to count the number of columns or words in a line
  • bash if statement how to test program output without assigning to variable
  • RTNETLINK answers: Network is unreachable
  • Centos 7 how to save iptables rules like Centos 6
  • nfs tuning maximum amount of connections
  • qemu-kvm error "Could not initialize SDL(No available video device) - exiting"
  • Centos 7 tftpd will not work with selinux enabled