Title: How to set a static IP address for a Linux system
- Centos OS 6.5
Vi/etc/sysconfig/network-scripts/ifcfg-<interface_alias_name>
Default modification:/etc/sysconfig/network-scripts/ifcfg-eth0
File:/etc/sysconfig/network-scripts/ifcfg-eth0
for eth0device=Eth0bootproto= none# This line ensures that the interface would be isbrought up during boot. Onboot= for most outbound connections.# the address, netmask, and gateway is all necessary. IPAddr=192.168. 100.5 NETMASK=255.255. 255.0 GATEWAY=198.168. 100.1
eth0 CodeFile:/etc/sysconfig/network-scripts/ifcfg-eth0:0
for eth0:0DEVICE=eth0:0Bootproto= none# This line ensures that the Interface'll is brought up during boot. Onboot=yes# eth0:0ipaddr=192.0. 2.6 NETMASK=255.255. 255.0
eth0:0 CodeFile:/etc/sysconfig/network-scripts/ifcfg-eth0:1
# Configuration for eth0:1 device =eth0:1 bootproto =none# this line ensures that the interface would be is brought up during boot. Onboot =yes# eth0: 1 # This is a private IP address. Private IPs do not having a gateway (they is Not publicly routable). # All need to specify are the address and netmaskipaddr =192 .168 . 133.234 netmask =255.255 . 128.0
eth0:1 CodeService Network restart
- Centos 7
Centos 7 no longer uses the "Network" service, you must create a/etc/sysconfig/network-scripts/ifcfg-eth0 file
File:/etc/sysconfig/network-scripts/ifcfg-eth0Device="eth0"HWADDR="00:21:70:10:7E:CD"nm_controlled="No"Onboot="Yes"Bootproto=static# Bootproto=dhcpipaddr=192.168.1.106NETMASK=255.255.255.0# # The GATEWAY is sometimesinch:/etc/sysconfig/Networkgateway=192.168.1.1
sample ' static assignment ' configuration Code
Linux Static IP Configuration