i and me好玩吗:【转】RedHat Linux下的网络配置基础

来源:百度文库 编辑:偶看新闻 时间:2024/05/04 19:15:41
Red Hat Linux 网络配置基础


#一:配置文件说明。


[root@redhatlinux9 root]# cat /etc/sysconfig/network
# CAT用来显示此文件 /etc/sysconfig/network ,此文件包含了主机的最基本网络信息,用于系统启动。
NETWORKING=yes
HOSTNAME=redhatlinux9
GATEWAY=192.168.1.1
# 比如以上显示了主机名和网关信息等。

[root@redhatlinux9 root]# vi /etc/sysconfig/networ
# 可以使用VI或者图形化界面来修改,其它配置文件也是一样。


[root@redhatlinux9 root]# cat /etc/sysconfig/network-scripts/
cat: /etc/sysconfig/network-scripts/: 是一个目录
# 此 目录 下包含系统启动时用来初始化网络的一些信息。
[root@redhatlinux9 root]# cd /etc/sysconfig/network-scripts/
# 进入此目录。
[root@redhatlinux9 network-scripts]# dir
# 可以看到很多文件。
ifcfg-eth0       ifdown-isdn   ifup-aliases   ifup-plusb    ifup-wireless
ifcfg-lo         ifdown-post   ifup-ippp      ifup-post     init.ipv6-global
ifdown           ifdown-ppp    ifup-ipv6      ifup-ppp      network-functions
ifdown-aliases   ifdown-sit    ifup-ipx       ifup-routes   network-functions-ipv6
ifdown-ippp      ifdown-sl     ifup-isdn      ifup-sit
ifdown-ipv6      ifup          ifup-plip      ifup-sl
[root@redhatlinux9 network-scripts]# cat ifcfg-eth0
# 如第一块以太网卡的文件为 ifcfg-eth0,用CAT命令显示可以看到:
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.216
NETMASK=255.255.255.0
GATEWAY=192.168.1.254
# 设备名、随启动运行、静态IP地址、IP地址为192.168.1.216、掩码255.255.255.0、网关192.168.1.254

[root@redhatlinux9 etc]# cat /etc/resolv.conf
# DNS客户端配置文件,此文件用于指定域名服务器地址。
nameserver 61.134.1.9
# 这里显示到此主机的DNS服务器地址为 61.134.1.9

#------基本上配置到这里,主机已经能够完成大部分网络连接任务了,诸如连接到INTERNET。------


[root@redhatlinux9 network-scripts]# cat /etc/hosts
# 主机名映射为IP地址的文件HOSTS。
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1        redhatlinux9     localhost.localdomain    localhost


[root@redhatlinux9 etc]# cat /etc/protocols
# 此文件设定了主机使用的协议一击各个协议的协议号。
# 内容计较长,可自行查看实验,这里就不列出了。


[root@redhatlinux9 etc]# cat /etc/services
# 此文件设定了主机的不同端口网络服务。
# 内容计较长,可自行查看实验,这里就不列出了。

#------以上三个文件很少需要配置,另外还有/etc下的 networks(域名与网络ID映射文件、host.conf等。


#########################################################################################
#二:网络配置工具。

#可以使用图形化配置程序,以下我们主要看一下命令行下的配置举例:

# ifconfig

[root@redhatlinux9 /]# ifconfig
# 用来检查网络配置。
lo         Link encap:Local Loopback
           inet addr:127.0.0.1   Mask:255.0.0.0
           UP LOOPBACK RUNNING   MTU:16436   Metric:1
           RX packets:13627 errors:0 dropped:0 overruns:0 frame:0
           TX packets:13627 errors:0 dropped:0 overruns:0 carrier:0
           collisions:0 txqueuelen:0
           RX bytes:929096 (907.3 Kb)   TX bytes:929096 (907.3 Kb)
# 本例中主机仅存在一个回环接口。

[root@redhatlinux9 /]# ifconfig eth0 192.168.1.216 netmask 255.255.255.0 up
# 设置本机第一块以太网接口的地址和掩码,最后的UP代表激活此设备。

[root@redhatlinux9 /]# ifconfig eth0 192.168.1.216
# 如果设备已经激活,可以直接设置地址。

[root@redhatlinux9 /]# ifconfig eth0 down
# DOWN命令用于关闭某个网络接口。

[root@redhatlinux9 /]# ifconfig eth0 up
# UP命令用来开启某个网络接口。

[root@redhatlinux9 /]# ifconfig eth0
# 可以查看指定的网络接口。
eth0       Link encap:Ethernet   HWaddr 00:0C:29:92:FB:33
           inet addr:192.168.1.216   Bcast:192.168.1.255   Mask:255.255.255.0
           UP BROADCAST RUNNING MULTICAST   MTU:1500   Metric:1
           RX packets:398 errors:0 dropped:0 overruns:0 frame:0
           TX packets:59 errors:0 dropped:0 overruns:0 carrier:0
           collisions:0 txqueuelen:100
           RX bytes:30699 (29.9 Kb)   TX bytes:9361 (9.1 Kb)
           Interrupt:10 Base address:0x1080


# route

[root@redhatlinux9 /]# route add default gw 192.168.1.254
# 添加缺省默认路由,主机接入互联网必需使用。

[root@redhatlinux9 /]# route add -host 192.168.1.1 dev eth0
# 添加到主机路由的方法,此处使用本地ETH0接口,视情况需要而添加。
[root@redhatlinux9 /]# route add -host 10.20.30.40 gw 192.168.1.254
# 添加到主机路由的方法,此时使用网关192.168.1.254,识情况需要而添加。

[root@redhatlinux9 /]# route add -net 192.168.0.0 netmask 255.255.255.0 eth0
# 添加到网络路由的方法,此处使用本地ETH0接口,可视情况需要而添加。
[root@redhatlinux9 /]# route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.1.254
# 添加到网络路由的方法,此处使用网关192.168.1.254,可视情况需要而添加。
[root@redhatlinux9 /]# route add -net 192.168.0.0/24 eth0
# 另一种到网络路由,掩码简写而已。

route del
# ROUTE DEL 命令用于删除路由。如route del -net 192.168.0.0 netmask 255.255.255.0 eth0
# 也就是route del 前面添加时写的语句。

route
# 显示本机路由表。


# ping

[root@redhatlinux9 /]# ping 192.168.1.216
PING 192.168.1.216 (192.168.1.216) 56(84) bytes of data.
64 bytes from 192.168.1.216: icmp_seq=1 ttl=64 time=0.094 ms
64 bytes from 192.168.1.216: icmp_seq=2 ttl=64 time=0.065 ms

--- 192.168.1.216 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.065/0.079/0.094/0.017 ms


# traceroute
# 追踪路由


# netstat

[root@redhatlinux9 /]# netstat -i
# 显示网络接口状态信息。

[root@redhatlinux9 /]# netstat -lpe
# 显示所由监控中的服务器的Socket和正在使用中的Socket的程序信息。

[root@redhatlinux9 /]# netstat -r
# 显示内核路由表信息。

[root@redhatlinux9 /]# netstat -nr
# 以纯地址形式显示内核路由表信息。

[root@redhatlinux9 /]# netstat -t
# 显示TCP传输协议的连接状态。

[root@redhatlinux9 /]# netstat -u
# 显示UDP协议的连接状态。


# hostname

[root@redhatlinux9 /]# hostname redhatlinux9
# 更改主机名。
[root@redhatlinux9 /]# hostname
# 显示主机名。


# arp

[root@redhatlinux9 /]# arp
# 查看ARP缓存

[root@redhatlinux9 /]# arp -s 192.168.1.13 00:50:ba:68:84:c3
# 添加一个静态绑定IP地址到MAC地址,可防止MAC地址盗用。

[root@redhatlinux9 /]# arp -d 192.168.1.13
# 删除一个对应缓存记录。