天天看點

網卡配置和DNS配置,手動挂在nas存儲的共享目錄,網絡相關其它操作指令,修改防火牆中的端口配置,resolv.conf配置詳細介紹和網卡資訊配置詳細介紹

 "ping:unknown host www.baidu.com" 

出現上面的原因主要是網絡的dns和網關不正确,需要進行如下操作:

a:修改/etc/resolv.conf中的内容,配置如下:

vim /etc/resolv.conf  修改裡面的内容:

resolv.conf的一個示例如下:

domain ringkee.com

search www.ringkee.com ringkee.com

nameserver 202.96.128.86

nameserver 202.96.128.166

b:配置/etc/sysconfig/network-scripts中的ifcfg-ethx,配置如下:

cd /etc/sysconfig/network-scripts

vim ifcfg-eth0

内容如下(可以在配置檔案中加上dns1和defroute配置):

device="eth0"

bootproto="static"

gateway="172.xx.xx.1"        #必須配置,可以使用ping指令ping一下

hwaddr="xx:xx:xx:xx:xx:xx"   #不能改動

ipaddr="172.xx.xx.81"        #伺服器的ip位址

netmask="xxx.xxx.252.0"      #滿足條件的子網路遮罩

nm_controlled="yes"

onboot="yes"

type="ethernet"

uuid="xxxx-xxxxx-xxxx-xxxx-xxxxx"  #不許變

同樣還得修改ifcfg-eth1中的内容(若有多塊網卡的情況下,配置說明如上)

gateway="172.xx.xx.1"

hwaddr="xx:xx:xx:xx:xx:xx"

ipaddr="172.xx.xx.81"

netmask="255.xx.xx.0"

uuid="xxxx-xxx-xxxx-xxx-xxxxx"

c:重新開機一下網絡,執行的指令為:

service network restart

或者執行:

/etc/init.d/network reload

注意:如果有些網絡環境需要停止伺服器上的防火牆,指令如下:

service iptables stop

d:此外,可以使用如下指令檢查網關配置和配置網關:

確定網關設定:

[root@oracle ~]# grep gateway /etc/sysconfig/network-scripts/ifcfg*

/etc/sysconfig/network-scripts/ifcfg-eth0:gateway=192.xxx.xx.1

如果未設定,則通過如下方式增加網關

route add default gw xxx.xxx.xxx.xxx     後面的一個ip是預設網關

重新開機一下網絡

service network restart 

確定可用dns解析

# grep hosts /etc/nsswitch.conf 

------------------------------------------------------------------- 

hosts:      files dns 

經過以上配置之後,再次ping 網絡,就可以ping通百度了

一般情況下,可以通過執行mount指令檢視磁盤挂載的資訊

挂載nas存儲的方式

進入要挂在磁盤上的伺服器,打開linux終端,執行如下指令

mount 172.xx.xx.xx:/ifs/data/kumannew /data

說明:

1、  ip為共享目錄的ip位址

2、  /data/kumannew為共享目錄的位置

3、  第三段的/data表示的意思是将/data/kumannew中的内容共享到/data目錄下面。

關于resolv.conf的關鍵字主要有4個,分别是:

nameserver

定義dns伺服器的ip位址

domain

定義本地域名

search

定義域名的搜尋清單

sortlist

對傳回的域名進行排序

注意:

上面最主要的是nameserver關鍵字,如果沒指定nameserver就找不到dns伺服器,其它關鍵字是可選的。

nameserver表示解析域名時使用該位址指定的主機為域名伺服器。其中域名伺服器是按照檔案中出現的順序來查詢的,且隻有當第一個nameserver沒有反應時才查詢下面的nameserver.

domain 聲明主機的域名。很多程式用到它。如郵件系統;當沒有域名的主機進行dns查詢時,也要用到。如果沒有域名,主機名将被使用,删除所在第一個(.)之前的内容。

sortlist 允許将得到域名結果進行特定的排序。它的參數為網絡/掩碼對,允許任意的排列順序。

有時候當我們配置好/etc/resolv.conf檔案後,發現重新開機後這個裡面的配置内容消失了,這時候可以将上面的dns的ip位址配置到/etc/sysconfig/network-scripts中的ifcfg-eth1或者ifcfg-eth0中。參考配置如下:

dns1=xxx.xxx.xxx.10   #resolv.conf中沒配置上的nameserver中的一個

defroute=yes

dns1=xxx.xxx.xxx.xxx

關于ifcfg-ethx的配置說明:

    /etc/sysconfig/network-script在這個目錄下面,存放的是網絡接口(網卡)的腳本檔案(控制檔案),ifcfg-eth0是預設的第一個網絡接口,如果機器中有多網絡接口,那麼名字就依次類推為:ifcfg-eth1,ifcfg-eth2,ifcfg-eth3…(這裡面的檔案相當重要,涉及到網絡能否正常工作)

關于網卡中的配置參數,詳細含義的介紹如下:、

device

接口名(裝置,網卡)

userctl

[yes|no]非root使用者是否可以控制該裝置

bootproto

ip的配置方法[none|static|bootp|dhcp](引導時不使用協定|靜态配置設定ip|boot協定|dhcp協定)

hwaddr

mac位址

onboot

系統啟動的時候網絡接口是否有效(yes/no)

type

網絡類型(通常是ethemet)

netmask

網絡掩碼

ipaddr

ip位址

ipv6init

ipv6是否有效(yes/no)

gateway

預設網關ip位址

broadcast

廣播位址

network

網絡位址

網卡接口關閉與激活

[root@localhost ~]# ifdown eth0   #關閉網絡(千萬小心操作,執行這個指令之後将不可以在使用遠端了)

[root@localhost ~]# ifup eth0     #啟動網絡

網絡服務啟動與關閉

方法一:

[root@localhost ~]# service network stop    #關閉網絡服務

[root@localhost ~]# service network start   #啟動網絡服務

[root@localhost ~]# service network restart #重新開機網絡服務

方法二:

[root@localhost ~]# /etc/init.d/network stop

[root@localhost ~]# /etc/init.d/network start

[root@localhost ~]# /etc/init.d/network restart 

網卡狀态查詢

[root@localhost ~]# service network status

configured devices:

lo eth0

currently active devices:

臨時配置網卡資訊,無需重新開機。

[root@localhost ~]# ifconfig eth0 10.1.1.10 netmask 255.0.0.0

檢視網卡接口資訊,預設列出所有接口

[root@localhost ~]# ifconfig

eth0      link encap:ethernet  hwaddr 00:0c:29:13:5d:74

          inet addr:192.168.1.11 bcast:192.168.1.255  mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fe13:5d74/64scope:link

          up broadcast running multicast mtu:1500  metric:1

          rx packets:413 errors:0 dropped:0 overruns:0frame:0

          tx packets:572 errors:0 dropped:0 overruns:0carrier:0

          collisions:0 txqueuelen:1000

          rx bytes:47701 (46.5 kib)  txbytes:64842 (63.3 kib)

          base address:0x2000memory:d8920000-d8940000 

lo        link encap:local loopback

          inet addr:127.0.0.1  mask:255.0.0.0

          inet6 addr: ::1/128 scope:host

          up loopback running  mtu:16436 metric:1

          rx packets:407 errors:0 dropped:0 overruns:0frame:0

          tx packets:407 errors:0 dropped:0 overruns:0carrier:0

          collisions:0 txqueuelen:0

          rx bytes:70759 (69.1 kib)  txbytes:70759 (69.1 kib)

檢視目前路由及網關資訊

[root@localhost ~]# netstat -r

kernel ip routing table

destination     gateway         genmask        flags   mss window  irtt iface

192.168.1.0     *              255.255.255.0   u         0 0         0 eth0

169.254.0.0     *              255.255.0.0     u         0 0         0 eth0

default         192.168.1.1     0.0.0.0        ug        0 0         0 eth0

dns:

主機名:centos

主dns:202.106.46.151

第二dns:202.106.0.20

第三dns:8.8.8.8

網絡配置:

eth0

靜态ip:192.168.1.106

子網路遮罩        255.255.255.0

預設網關 ip     192.168.1.1

device=eth0

ipaddr=192.168.1.106

netmask=255.255.255.0

broadcast=192.168.1.255

onboot=yes

bootproto=none

gateway=192.168.1.1

type=ethernet

vi/etc/sysconfig/iptables 

-a input -m state –state new -m tcp -p tcp–dport 80 -j accept(允許80端口通過防火牆) 

-a input -m state –state new -m tcp -p tcp–dport 3306 -j accept(允許3306端口通過防火牆) 

特别提示:很多網友把這兩條規則添加到防火牆配置的最後一行,導緻防火牆啟動失敗,正确的應該是添加到預設的22端口這條規則的下面 

添加好之後防火牆規則如下所示: 

# firewall configuration written by system-config-firewall

# manual customization of this file is not recommended.

*filter

:input accept [0:0]

:forward accept [0:0]

:output accept [0:0]

-a input -m state –state established,related -j accept

-a input -p icmp -j accept

-a input -i lo -j accept

-a input -m state –state new -m tcp -p tcp –dport 22 -j accept

-a input -m state –state new -m tcp -p tcp –dport 80 -j accept

-a input -m state –state new -m tcp -p tcp –dport 3306 -j accept

-a input -j reject –reject-with icmp-host-prohibited

-a forward -j reject –reject-with icmp-host-prohibited

commit

/etc/init.d/iptables restart 

#最後重新開機防火牆使配置生效

關閉防火牆的方式: