Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

Linux 下 IP 與預設閘道的即時及開機生效設定

現在圖形介面下改網路很簡單,但背後的原理值得知道。以下示範指令方式。


改 IP 位址

即時生效:

# ifconfig eth0 192.168.1.102 netmask 255.255.255.0

開機生效:編輯 /etc/sysconfig/network-scripts/ifcfg-eth0,加入

     IPADDR=192.168.1.102
     NETMASK=255.255.255.0

改預設閘道

即時生效:

# route add default gw 192.168.1.1

開機生效:同一支 ifcfg-eth0 裡加入

    GATEWAY=192.168.1.1

最終樣貌

    DEVICE=eth0
    BOOTPROTO=static
    IPADDR=192.168.1.102
    NETMASK=255.255.255.0
    GATEWAY=192.168.1.1
    ONBOOT=yes
    TYPE=Ethernet

提醒:BOOTPROTO 只有在 static(靜態)模式下,上面設定的 IP 資訊才會被採用。

Copyright © Linux教程網 All Rights Reserved