linux下設定ip地址 gw網關,dns的方法

來源:互聯網
上載者:User

標籤:

本文介紹下,在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的方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.