標籤:
本文介紹下,在linux中設定IP地址、網關、dns的方法,有需要的朋友作個參考吧。
設定linux網路的方法有兩種:
第一種:使用命令修改(直接即時生效)
複製代碼程式碼範例:
ip and netmask:
# ifconfig eth0 192.168.30.197 netmask 255.255.255.0
gateway:
# route add default gw 192.168.30.1 eth0
dns:
# vi etc/resolv.conf
nameserver 202.131.80.1
nameserver 202.131.80.5
第二種:修改配置文檔(需要重啟網路設定)
一、修改IP地址
複製代碼程式碼範例:[[email protected] network-scripts]$ vi ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.30.197
NETMASK=255.255.255.0
GATEWAY=192.168.30.1
二、修改網關
vi /etc/sysconfig/network
複製代碼程式碼範例:NETWORKING=yes
HOSTNAME=Aaron
GATEWAY=192.168.30.1
三、修改DNS
複製代碼程式碼範例:[[email protected]db1 etc]$ vi resolv.conf
nameserver 202.131.80.1
nameserver 202.131.80.5
(一般現在這樣設定以後都要重啟network,所以還涉及到網路重啟配置)
四、重新啟動網路設定
方法有多種:
複製代碼程式碼範例:1:root賬戶下 # service network restart
2:# /etc/init.d/network restart
3:# ifdown eth0
# ifup eth0
4:# ifconfig eth0 down
# ifconfig eth0 up
五、啟動和關閉防火牆
即時生效:
複製代碼程式碼範例:1:#service iptables start
#service iptables stop
重啟系統生效:
複製代碼程式碼範例:2:#service iptables on
#service iptables off
linux下設定ip地址 gw網關,dns的方法