在Linux系統中修改IP地址

    在Linux系統中,通過編輯網絡配置文件,設置系統IP地址,當然要在root權限下執行,具體步驟如下:

1、切換路徑到/etc/sysconfig/network-scripts

[root@Compile network-scripts]# pwd
/etc/sysconfig/network-scripts

2、查看ifcfg-eth0文件屬性,確保具有編輯權限

[root@Compile network-scripts]# ls -l ifcfg-eth0
-rw-r--r--. 1 root root 258 9月  24 18:05 ifcfg-eth0

3、編輯文件ifcfg-eth0,添加如下信息

ONBOOT=yes

BOOTPROTO=static

IPADDR=192.168.30.175

NETMASK=255.255.255.0

GATEWAY=192.168.30.1

命令如下:[root@Compile network-scripts]# vi ifcfg-eth0

DEVICE=eth0
TYPE=Ethernet
UUID=9d3f1462-d7ac-49fe-8b1b-d729866d3bc7
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
HWADDR=00:23:AE:A8:D7:1E
IPADDR=192.168.30.175
NETMASK=255.255.255.0
GATEWAY=192.168.30.1
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"

4、重啓網絡服務

[root@Compile network-scripts]# /etc/init.d/network  restart
正在關閉接口 eth0: 設備狀態:3 (斷開連接)
                                                           [確定]
關閉環回接口:                                             [確定]
彈出環回接口:                                             [確定]
彈出界面 eth0: 活躍連接狀態:激活的
活躍連接路徑:/org/freedesktop/NetworkManager/ActiveConnection/2
                                                           [確定]

5、通過命令方式設置網絡IP,可以立即生效

[root@Compile network-scripts]# ifconfig eth0 192.168.30.175 netmask 255.255.255.0

[root@Compile network-scripts]# route add default gateway 192.168.30.1

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章