如题:如何给Linux系统设置静态IP地址
- Centos OS 6.5
vi /etc/sysconfig/network-scripts/ifcfg-<interface_alias_name>
默认修改:/etc/sysconfig/network-scripts/ifcfg-eth0File: /etc/sysconfig/network-scripts/ifcfg-eth0
# Configuration for eth0 DEVICE=eth0 BOOTPROTO=none # This line ensures that the interface will be brought up during boot. ONBOOT=yes # eth0 - This is the main IP address that will be used for most outbound connections. # The address, netmask, and gateway are all necessary. IPADDR=192.168.100.5 NETMASK=255.255.255.0 GATEWAY=198.168.100.1
eth0 Code
File: /etc/sysconfig/network-scripts/ifcfg-eth0:0
# Configuration for eth0:0 DEVICE=eth0:0 BOOTPROTO=none # This line ensures that the interface will be brought up during boot. ONBOOT=yes # eth0:0 IPADDR=192.0.2.6 NETMASK=255.255.255.0
eth0:0 Code
File: /etc/sysconfig/network-scripts/ifcfg-eth0:1
# Configuration for eth0:1 DEVICE=eth0:1 BOOTPROTO=none # This line ensures that the interface will be brought up during boot. ONBOOT=yes # eth0:1 # This is a private IP address. Private IPs do not have a gateway (they are not publicly routable). # All you need to specify is the address and netmask IPADDR=192.168.133.234 NETMASK=255.255.128.0
eth0:1 Code
service network restart
- Centos 7
Centos 7 不再使用"Network"服务, 你必须创建/etc/sysconfig/network-scripts/ifcfg-eth0文件
File: /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0" HWADDR="00:21:70:10:7E:CD" NM_CONTROLLED="no" ONBOOT="yes" BOOTPROTO=static # BOOTPROTO=dhcp IPADDR=192.168.1.106 NETMASK=255.255.255.0 # # the GATEWAY is sometimes in: /etc/sysconfig/network GATEWAY=192.168.1.1
sample ‘static assignment‘ configuration Code
时间: 2024-10-12 10:26:18