ifconfig
查看所有活动网络接口的信息执行 ifconfig命令
查看指定网络接口信息格式:ifconfig 网络接口名
名称类型Eth0以太网Lo(虚拟)回环设备ppp0使用PPP协议的串口设备(通常指调制解调器)Tr0令牌环(Token Ring)Fddi0光纤hostname
查看或设置当前主机名格式:hostname [root@localhost ~]# hostname localhost.localdomainroute
查看或设置主机中路由表信息格式:route [-n] [root@localhost ~]# route -n -n:将路由记录中的地址信息显示为数字形式 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.4.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 0.0.0.0 192.168.4.1 0.0.0.0 UG 0 0 0 eth0netstat
查看系统的网络连接状态、路由表、接口统计等信息格式:netstat{选项]常用选项: -a:显示所有活动连接 -n:以数字形式显示 -p:显示进程信息 -t:查看TCP协议相关信息 -u:查看UDP协议相关信息 -r:显示路由表信息 [root@localhost ~]# netstat -anpt | grep :21 tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 1774/vsftpdtraceroute
测试从当前主机到目的主机之间经过的网络节点格式:traceroute 目标主机地址 [root@localhost ~]# traceroute 192.168.7.7 traceroute to 192.168.7.7 (192.168.7.7), 30 hops max, 40 byte packets 1 (192.168.4.1) 7.740 ms 15.581 ms 15.881 ms 2 (192.168.7.7) 19.652 ms 19.995 ms 19.942 ms格式: ifconfig 接口名 IP地址 [netmask 子网掩码] ifconfig 网络接口 IP地址[/掩码长度]
禁用或者重新激活网卡格式: ifconfig 网络接口 up ifconfig 网络接口 down
设置虚拟网络接口格式: ifconfig 接口名:序号 IP地址
格式: route del default gw ip地址
向路由表中添加默认网关记录格式: route add default gw ip地址
添加到指定网段的路由记录格式: route add -net 网段地址 gw ip地址
删除到指定网段的路由记录格式: route del -net 网段地址
ifcfg-eth0:第1块以太网的配置文件 ifcfg-eth1:第2块以太网的配置文件 ……
[root@localhost ~]# ls /etc/sysconfig/network-scripts/ifcfg-* /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-lo自定义的变量名称建议全部大写
[root@localhost ~]#vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 ONBOOT=yes BOOTPROTO=static IPADDR=192.168.4.1 NETMASK=255.255.255.0 GATEWAY=192.168.4.2用途:保存全局网络设置,主要包括主机名信息
[root@localhost ~]# vi /etc/sysconfig/network NETWORKING=yes NETWORKING_IPV6=no HOSTNAME=www.qwfy.com用途:保存本机需要使用的DNS服务器的IP地址
[root@localhost ~]# vi /etc/resolv.conf search localdomain nameserver 202.106.0.20 nameserver 202.106.148.1注意: 1、“search localdomain”行用来设置默认的搜索域 2、最多支持三个不同的DNS服务器地址
用途:保存主机名与ip地址的映射记录
[root@localhost ~]# cat /etc/hosts 127.0.0.1 localhost.localdomain localhost …… 119.75.218.70 www.baidu.com hosts文件和DNS服务器的比较 默认情况下,系统首先从hosts文件下查找解析记录hosts文件只对当前的主机有效hosts文件可减少DNS查询过程,从而加快访问速度ethtool -i <接口名>
显示网络数据ethtool -S
设置适配器连接速度(Mbps)ethtool speed <10|100|1000>
RHEL5光盘中的 dhcp-3.0.5-23.el5.i386.rpm
DHCP软件包的主要文件 主配置文化:/etc/dhcp/dhcp.conf执行程序:/usr/sbin/dhcpd、 /usr/sbin/dhcrelay服务脚本:/etc/rc.d/init.d/dhcpd、 /etc/rc.d/init.d/dhcrelay执行参数配置:/etc/susconfig/dhcpdDHCP中继配置:/etc/sysconfig/dhcrelayrange参数:设置用于分配的ip地址池
option subnet-mask参数:设置客户机的子网掩码
option routers参数:设置客户机的默认网关地址
[root@localhost ~]# vi /etc/dhcpd.conf subnet 192.168.4.0 netmask 255.255.255.0 { 声明网段地址 range 192.168.4.128 192.168.4.254; 设置地址池 option subnet-mask 255.255.255.0; 设置子网掩码 option routers 192.168.4.1; 指定默认网关地址 } host主机声明,作用于单个主机hardware ethernet参数:指定对应主机的MAC地址
fixed-address参数:指定为该主机保留的IP地址
host prtsvr { hardware ethernet 00:c0:c3:22:46:81; fixed-address 192.168.4.100; }两种使用方式
修改网卡配置文件(如ifcfg-eth0)BOOTPROTO=dhcp
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 DHCP发现 ONBOOT=yes DHCP提供 BOOTPROTO=dhcp DHCP请求 [root@localhost ~]# ifdown eth0 ; ifup eth0 DHCP确认 Determining IP information for eth0… done. 使用dhclient命令dhclient [-d] [网络接口名]
[root@localhost ~]# dhclient -d 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:ae:1c:25 Sending on LPF/eth0/00:0c:29:ae:1c:25 Sending on Socket/fallback DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 8 DHCP发现 DHCPOFFER from 192.168.4.11 DHCP提供 DHCPREQUEST on eth0 to 255.255.255.255 port 67 DHCP请求 DHCPACK from 192.168.4.11 DHCP确认 bound to 192.168.4.254 -- renewal in 9220 seconds.dhclient -r 释放获取的IP地址