Linux Static IP Configuration

如题:如何给Linux系统设置静态IP地址

  1. Centos OS 6.5
    vi /etc/sysconfig/network-scripts/ifcfg-<interface_alias_name>  
    默认修改:/etc/sysconfig/network-scripts/ifcfg-eth0

    File: /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

  2. 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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。