本文共 8898 字,大约阅读时间需要 29 分钟。
· /etc/hosts
这个文件用于设置主机名与 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
· /etc/sysconfig/network
- [root@rhel6 ~]# cat /etc/sysconfig/network
- NETWORKING=yes
- HOSTNAME=rhel6.xfcy.org
-
- [root@rhel6 ~]# hostname
- rhel6.xfcy.org
· /etc/sysconfig/network-script/ifcfg-<interface-name>
每一个网络接口,都有一个与之对应用的配置脚本,这些脚本文件为相应的网络接口设置指定的配置信息。 - [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 指令中配置的通道绑定接口进行控制
· /etc/resolv.conf
这个文件用于设置 DNS 的 IP 地址和搜索域,除非另行配置,否则网络初始化脚本总是使用这个文档中的配置信息 - [root@rhel6 ~]# cat /etc/resolv.conf
- search xfcy.org
- nameserver 8.8.8.8 #RHEL6中重启后则消失
- nameserver 8.8.4.4
==============================================================================================
==============================================================================================
· 客户端通过DHCP自动获取IP地址
- [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:
-
- 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
· 路由配置
- [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
- Kernel IP routing table
- Destination Gateway Genmask Flags Metric Ref Use Iface
- 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
- [root@rhel6 ~]# route -n
- Kernel IP routing table
- Destination Gateway Genmask Flags Metric Ref Use Iface
- 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.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
- Kernel IP routing table
- Destination Gateway Genmask Flags Metric Ref Use Iface
- 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
- 192.168.3.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0
- 192.168.1.0 * 255.255.255.0 U 1 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) :这个路由将不会被接受(用来抵挡不安全的网域!)
==============================================================================================
· 网络参数综合指令:ip
- # 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
- valid_lft forever preferred_lft forever
- [root@rhel6 ~]# ip address add 192.168.2.119/24 broadcast + dev eth0 label eth0:alias #临时手动添加一条IP别名
- [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
- inet 192.168.2.119/24 brd 192.168.2.255 scope global eth0:alias
- inet6 fe80::20c:29ff:febf:4580/64 scope link
- valid_lft forever preferred_lft forever
-
- [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
- 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
- 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
- [root@rhel6 ~]# ip -s link show eth0
- 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
- 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
- link/ether 00:0c:29:bf:45:80 brd ff:ff:ff:ff:ff:ff
- [root@rhel6 ~]# ip link set eth0 up
- [root@rhel6 ~]# ip link show eth0
- 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
- # 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
- [root@rhel6 ~]# ip route show
- 192.168.3.0/24 dev eth0 scope link
- 192.168.2.0/24 via 192.168.1.1 dev eth0
- 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.119 metric 1
- default via 192.168.1.1 dev eth0
-
- [root@rhel6 ~]# route -n
- Kernel IP routing table
- Destination Gateway Genmask Flags Metric Ref Use Iface
- 192.168.3.0 0.0.0.0 255.255.255.0 U 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 ~]# ip route del 192.168.3.0/24
- [root@rhel6 ~]# ip route del default
- [root@rhel6 ~]# ip route show
- 192.168.2.0/24 via 192.168.1.1 dev eth0
- 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.119 metric 1
-
- [root@rhel6 ~]# route -n
- Kernel IP routing table
- Destination Gateway Genmask Flags Metric Ref Use Iface
- 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
转载地址:http://tgaul.baihongyu.com/