· <b>/etc/hosts</b>
這個檔案用于設定主機名與 IP 映射關系,為那些無法通過其它方式 (如通過 DNS 伺服器) 解析的主機名進行解析
[root@rhel6 ~]# cat /etc/hosts
127.0.0.1 localhost.localdomain localhost
192.168.1.119 rhel6.xfcy.org rhel6
192.168.1.90 rhel5.xfcy.org rhel5
192.168.1.11 rhel5-1.xfcy.org rhel5-1
192.168.1.22 rhel5-2.xfcy.org rhel5-2
· <b>/etc/sysconfig/network</b>
這個檔案用于為所有網絡接口設定路由和主機資訊。
[root@rhel6 ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=rhel6.xfcy.org
[root@rhel6 ~]# hostname
rhel6.xfcy.org
· <b>/etc/sysconfig/network-script/ifcfg-<interface-name></b>
每一個網絡接口,都有一個與之對應用的配置腳本,這些腳本檔案為相應的網絡接口設定指定的配置資訊。
[root@rhel6 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes #系統啟動時是否激活裝置
NM_CONTROLLED=yes #是否被NetworkManager的服務控制
DEFROUTE=yes #是否把這個eth設定為預設路由
BOOTPROTO=none #none | dhcp | static
HWADDR=00:0C:29:BF:45:80 #硬體位址(一般與下面的MACADD相同)
#MACADDR=60:EB:69:FC:4D:98 #MAC位址(如要修改網卡MAC位址必須修改該選項)
IPADDR=192.168.1.119
NETWORK=255.255.255.0
GATEWAY=192.168.1.1
#IPADDR2=192.168.2.119
#NETWORK=255.255.255.0
DNS1=8.8.8.8
DNS2=8.8.4.4
PEERDNS=yes #是否生效DNS配置資訊(将自動修改/etc/resolv.conf中nameserver的值,設為no則DNS由/etc/resolv.conf中配置的值來控制 )
USERCTL=yes #允許非 root 使用者控制這個裝置
MASTER=bond0 #bond0是以太網卡連接配接到的通道綁定接口的名稱,這個指令與 SLAVE 指令配合使用。
SLAVE=<yes|no> #此裝置是否可以由 MASTER 指令中配置的通道綁定接口進行控制
· <b>/etc/resolv.conf</b>
這個檔案用于設定 DNS 的 IP 位址和搜尋域,除非另行配置,否則網絡初始化腳本總是使用這個文檔中的配置資訊
[root@rhel6 ~]# cat /etc/resolv.conf
search xfcy.org
nameserver 8.8.8.8 #RHEL6中重新開機後則消失
nameserver 8.8.4.4
==============================================================================================
· <b>用戶端通過DHCP自動擷取IP位址</b>
[root@rhel5 ~]# dhclient eth0
Internet Systems Consortium DHCP Client V3.0.5-RedHat
Copyright 2004-2006 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
Listening on LPF/eth0/00:0c:29:db:14:10
Sending on LPF/eth0/00:0c:29:db:14:10
Sending on Socket/fallback
DHCPOFFER from 192.168.1.119
DHCPREQUEST on eth0 to 255.255.255.255 port 67
DHCPACK from 192.168.1.119
bound to 192.168.1.90 -- renewal in 9863 seconds.
[root@rhel6 ~]# tail -f /var/log/messages
Nov 20 14:03:55 rhel6 dhcpd: DHCPREQUEST for 192.168.1.90 from 00:0c:29:db:14:10 via eth0
Nov 20 14:03:55 rhel6 dhcpd: DHCPACK on 192.168.1.90 to 00:0c:29:db:14:10 via eth0
· <b>路由配置</b>
[root@rhel6 ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 1 0 0 eth0
[root@rhel6 ~]# route add default gw 192.168.1.1
[root@rhel6 ~]# route add -net 192.168.2.0/24 gw 192.168.1.1
[root@rhel6 ~]# route add -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.1.1
[root@rhel6 ~]# route add -net 192.168.4.0/24 dev eth0
[root@rhel6 ~]# route add -host 192.168.5.90 dev eth0
[root@rhel6 ~]# route -n
192.168.5.90 0.0.0.0 255.255.255.255 UH 0 0 0 eth0
192.168.4.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.3.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0
192.168.2.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
[root@rhel6 ~]# route del -net 192.168.2.0/24 gw 192.168.1.1
192.168.5.90 * 255.255.255.255 UH 0 0 0 eth0
192.168.4.0 * 255.255.255.0 U 0 0 0 eth0
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
***************************** Flags中的辨別代表意義: ***************************
U (route is up) :該路由是啟動的;
H (target is a host) :目标是一部主機 (IP) 而非網域;
G (use gateway) :需要透過外部的主機 (gateway) 來轉遞封包;
R (reinstate route for dynamic routing) :使用動态路由時,恢複路由資訊的旗标;
D (dynamically installed by daemon or redirect) :已經由服務或轉 port 功能設定為動态路由
M (modified from routing daemon or redirect) :路由已經被修改了;
! (reject route) :這個路由将不會被接受(用來抵擋不安全的網域!)
· <b>網絡參數綜合指令:ip</b>
# ip [option] [動作] [指令]
option :設定的參數,主要有:
-s :顯示出該裝置的統計資料(statistics),例如總接受封包數等;
動作 :亦即是可以針對哪些網絡參數進行動作,包括有:
address :關于額外的 IP 協定,例如多 IP 的達成等等;
link :關于device 的相關設定,包括 MTU, MAC 位址等等
route :與路由有關的相關設定
# ip address show
# ip address [add|del] [IP] [dev device] [相關參數]
相關參數:
broadcast :設定廣播位址,如果設定值是 + 表示讓系統自動計算
label :亦即是這個裝置的别名,例如 eth0:0 就是了!
scope :這個界面的領域,通常是這幾個大類:
global :允許來自所有來源的聯機(default);
site :僅支援 IPv6 ,僅允許本主機的聯機;
link :僅允許本裝置自我聯機;
host :僅允許本主機内部的聯機;
[root@rhel6 ~]# ip add show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:bf:45:80 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.119/24 brd 192.168.1.255 scope global eth0
inet6 fe80::20c:29ff:febf:4580/64 scope link
[root@rhel6 ~]# ip address add 192.168.2.119/24 broadcast + dev eth0 label eth0:alias #臨時手動添加一條IP别名
inet 192.168.2.119/24 brd 192.168.2.255 scope global eth0:alias
[root@rhel6 ~]# ifconfig eth0:alias
eth0:alias Link encap:Ethernet HWaddr 00:0C:29:BF:45:80
inet addr:192.168.2.119 Bcast:192.168.2.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
[root@rhel6 ~]# ip add del 192.168.2.119/24 dev eth0 #臨時手動删除一條IP别名
# ip [-s] link show
# ip link set [device] [動作與參數]
動作與參數:包括有底下的這些動作:
up|down :啟動 (up) 或關閉 (down) 某個接口,其他參數使用預設的以太網
address :修改 MAC 位址
name :給予這個裝置一個特殊的名字;
mtu :最大傳輸單元
[root@rhel6 ~]# ip link show
[root@rhel6 ~]# ip -s link show eth0
RX: bytes packets errors dropped overrun mcast
1284926 15957 0 0 0 0
TX: bytes packets errors dropped carrier collsns
5592979 11652 0 0 0 0
[root@rhel6 ~]# ip link set eth0 down
[root@rhel6 ~]# ip link show eth0
2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state Down qlen 1000
[root@rhel6 ~]# ip link set eth0 up
[root@rhel6 ~]# ip link show eth0
# ip route show
# ip route [add|del] [IP] [via gateway] [dev device]
[root@rhel6 ~]# ip route show
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.119 metric 1
[root@rhel6 ~]# ip route add 192.168.2.0/24 via 192.168.1.1
[root@rhel6 ~]# ip route add 192.168.3.0/24 dev eth0
[root@rhel6 ~]# ip route add default via 192.168.1.1 dev eth0
192.168.3.0/24 dev eth0 scope link
192.168.2.0/24 via 192.168.1.1 dev eth0
default via 192.168.1.1 dev eth0
192.168.3.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
[root@rhel6 ~]# ip route del 192.168.3.0/24
[root@rhel6 ~]# ip route del default
[root@rhel6 ~]# ip route show
本文轉自Vnimos51CTO部落格,原文連結:http://blog.51cto.com/vnimos/1064758,如需轉載請自行聯系原作者