一、查看及测试网络配置
1.查看网络接口信息
ifconfig [-a] [接口名] -a 查看所有接口,不论接口是否活跃 [接口名] 只显指定接口
- [root@localhost ~]# ifconfig -a
- eth0 Link encap:Ethernet HWaddr 00:0C:29:75:78:09
- inet addr:192.168.2.2 Bcast:192.168.2.255 Mask:255.255.255.0
- inet6 addr: fe80::20c:29ff:fe75:7809/64 Scope:Link
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
- RX packets:97692 errors:0 dropped:0 overruns:0 frame:0
- TX packets:507 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:5901878 (5.6 MiB) TX bytes:101999 (99.6 KiB)
- Interrupt:59 Base address:0x2000
- 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:24 errors:0 dropped:0 overruns:0 frame:0
- TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:1904 (1.8 KiB) TX bytes:1904 (1.8 KiB)
- sit0 Link encap:IPv6-in-IPv4
- NOARP MTU:1480 Metric:1
- RX packets:0 errors:0 dropped:0 overruns:0 frame:0
- TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
- [root@localhost ~]# ifconfig eth0
- eth0 Link encap:Ethernet HWaddr 00:0C:29:75:78:09
- inet addr:192.168.2.2 Bcast:192.168.2.255 Mask:255.255.255.0
- inet6 addr: fe80::20c:29ff:fe75:7809/64 Scope:Link
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
- RX packets:97860 errors:0 dropped:0 overruns:0 frame:0
- TX packets:548 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:5912602 (5.6 MiB) TX bytes:107449 (104.9 KiB)
- Interrupt:59 Base address:0x2000
2.测试网络连接状态 ping [-c 次数] 目标主机IP或名称
- [root@localhost ~]# ping -c 1 192.168.1.1
- PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
- 64 bytes from 192.168.1.1: icmp_seq=1 ttl=63 time=2.00 ms
- --- 192.168.1.1 ping statistics ---
- 1 packets transmitted, 1 received, 0% packet loss, time 0ms
- rtt min/avg/max/mdev = 2.001/2.001/2.001/0.000 ms
- [root@localhost ~]# ping -c 2 192.168.2.2
- PING 192.168.2.2 (192.168.2.2) 56(84) bytes of data.
- 64 bytes from 192.168.2.2: icmp_seq=1 ttl=64 time=0.017 ms
- 64 bytes from 192.168.2.2: icmp_seq=2 ttl=64 time=0.020 ms
- --- 192.168.2.2 ping statistics ---
- 2 packets transmitted, 2 received, 0% packet loss, time 1015ms
- rtt min/avg/max/mdev = 0.017/0.018/0.020/0.004 ms
3.查看主机路由信息 route [-n] -n 使用数字显示(速度比较快)
- [root@localhost ~]# route -n
- Kernel IP routing table
- Destination Gateway Genmask Flags Metric Ref Use Iface
- 192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
- 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
- 0.0.0.0 192.168.2.1 0.0.0.0 UG 0 0 0 eth0
- [root@localhost ~]# netstat -rn
- Kernel IP routing table
- Destination Gateway Genmask Flags MSS Window irtt Iface
- 192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
- 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
- 0.0.0.0 192.168.2.1 0.0.0.0 UG 0 0 0 eth0
4.跟踪数据包所经过的路由 traceroute 目标主机IP或名称
- [root@localhost ~]# traceroute 192.168.1.1
- traceroute to 192.168.1.1 (192.168.1.1), 30 hops max, 40 byte packets
- 1 (192.168.2.1) 0.396 ms 0.365 ms 0.332 ms
5.查看主机名称 hostname
- [root@localhost ~]# hostname
- localhost.localdomain
6.测试DNS服务器是否能正常解析
nslookup 目标主机名或IP [DNS服务器IP]
- [root@localhost ~]# nslookup www.baidu.com
- Server: 192.168.222.2
- Address: 192.168.222.2#53
- Non-authoritative answer:
- www.baidu.com canonical name = www.a.shifen.com.
- Name: www.a.shifen.com
- Address: 119.75.218.77
- Name: www.a.shifen.com
- Address: 119.75.217.56
- [root@localhost ~]# nslookup www.google.com
- Server: 192.168.222.2
- Address: 192.168.222.2#53
- Non-authoritative answer:
- www.google.com canonical name = www.l.google.com.
- Name: www.l.google.com
- Address: 74.125.128.147
- Name: www.l.google.com
- Address: 74.125.128.99
- Name: www.l.google.com
- Address: 74.125.128.103
- Name: www.l.google.com
- Address: 74.125.128.104
- Name: www.l.google.com
- Address: 74.125.128.105
- Name: www.l.google.com
- Address: 74.125.128.106
7.查看网络连接状态
netstat [-anrltup]
-a显示所有连接 -n用数字显示 -r显示路由表 -l显示处于监听状态的进程
-t显示TCP进程 -u显示UDP进程 -p显示进程号进程名信息
- [root@localhost ~]# netstat -a
- Active Internet connections (servers and established)
- Proto Recv-Q Send-Q Local Address Foreign Address State
- tcp 0 0 *:sunrpc *:* LISTEN
- tcp 0 0 *:ssh *:* LISTEN
- getnameinfo failed
- getnameinfo failed
- tcp 0 0 [UNKNOWN]:ssh [UNKNOWN]:49913 ESTABLISHED
- getnameinfo failed
- getnameinfo failed
- tcp 0 0 [UNKNOWN]:ssh [UNKNOWN]:56922 ESTABLISHED
- getnameinfo failed
- getnameinfo failed
- tcp 0 5396 [UNKNOWN]:ssh [UNKNOWN]:56588 ESTABLISHED
- udp 0 0 *:47133 *:*
- udp 0 0 *:mdns *:*
- udp 0 0 *:sunrpc *:*
- udp 0 0 *:41938 *:*
- udp 0 0 *:mdns *:*
- raw 0 0 *:icmp *:* 7
- raw 0 0 *:icmp *:* 7
- Active UNIX domain sockets (servers and established)
- Proto RefCnt Flags Type State I-Node Path
- unix 2 [ ACC ] STREAM LISTENING 7453 /var/run/acpid.socket
- unix 2 [ ACC ] STREAM LISTENING 7726 /tmp/.font-unix/fs7100
- unix 2 [ ACC ] STREAM LISTENING 48069 /tmp/ssh-AEZfUj4473/agent.4473
- unix 2 [ ACC ] STREAM LISTENING 48155 /tmp/ssh-zzVwKC4508/agent.4508
- unix 2 [ ACC ] STREAM LISTENING 9324 @/tmp/fam-root-
- unix 2 [ ACC ] STREAM LISTENING 50663 /tmp/ssh-uUKGrr6628/agent.6628
- unix 2 [ ACC ] STREAM LISTENING 7691 /dev/gpmctl
- unix 2 [ ACC ] STREAM LISTENING 7914 /var/run/avahi-daemon/socket
- unix 2 [ ACC ] STREAM LISTENING 7960 @/var/run/hald/dbus-OlENpyyvWV
- unix 2 [ ] DGRAM 1474 @/org/kernel/udev/udevd
- unix 2 [ ] DGRAM 7968 @/org/freedesktop/hal/udev_event
- unix 2 [ ACC ] STREAM LISTENING 7959 @/var/run/hald/dbus-EksVbyIVuK
- unix 14 [ ] DGRAM 6838 /dev/log
- unix 2 [ ACC ] STREAM LISTENING 6841 /var/run/audispd_events
- unix 2 [ ACC ] STREAM LISTENING 7171 /var/run/dbus/system_bus_socket
- unix 2 [ ACC ] STREAM LISTENING 7312 /var/run/pcscd.comm
- unix 2 [ ] DGRAM 50655
- unix 2 [ ] DGRAM 48147
- unix 2 [ ] DGRAM 48061
- unix 3 [ ] STREAM CONNECTED 9327 @/tmp/fam-root-
- unix 3 [ ] STREAM CONNECTED 9326
- unix 3 [ ] STREAM CONNECTED 9316 /var/run/dbus/system_bus_socket
- unix 3 [ ] STREAM CONNECTED 9315
- unix 3 [ ] STREAM CONNECTED 9127 /var/run/dbus/system_bus_socket
- unix 3 [ ] STREAM CONNECTED 9126
- unix 3 [ ] STREAM CONNECTED 9101 @/var/run/hald/dbus-EksVbyIVuK
- unix 3 [ ] STREAM CONNECTED 9100
- unix 3 [ ] STREAM CONNECTED 9092 /var/run/acpid.socket
- unix 3 [ ] STREAM CONNECTED 9091
- unix 3 [ ] STREAM CONNECTED 9082 @/var/run/hald/dbus-EksVbyIVuK
- unix 3 [ ] STREAM CONNECTED 9081
- unix 3 [ ] STREAM CONNECTED 8926 @/var/run/hald/dbus-EksVbyIVuK
- unix 3 [ ] STREAM CONNECTED 8924
- unix 3 [ ] STREAM CONNECTED 7963 @/var/run/hald/dbus-OlENpyyvWV
- unix 3 [ ] STREAM CONNECTED 7962
- unix 3 [ ] STREAM CONNECTED 7917 /var/run/dbus/system_bus_socket
- unix 3 [ ] STREAM CONNECTED 7916
- unix 3 [ ] STREAM CONNECTED 7911
- unix 3 [ ] STREAM CONNECTED 7910
- unix 2 [ ] DGRAM 7908
- unix 2 [ ] DGRAM 7681
- unix 2 [ ] DGRAM 7650
- unix 2 [ ] DGRAM 7615
- unix 2 [ ] DGRAM 7399
- unix 2 [ ] DGRAM 7345
- unix 2 [ ] DGRAM 7284
- unix 3 [ ] STREAM CONNECTED 7175
- unix 3 [ ] STREAM CONNECTED 7174
- unix 3 [ ] STREAM CONNECTED 7111
- unix 3 [ ] STREAM CONNECTED 7110
- unix 2 [ ] DGRAM 6849
- unix 2 [ ] DGRAM 6840
- unix 3 [ ] STREAM CONNECTED 6768
- unix 3 [ ] STREAM CONNECTED 6767
- [root@localhost ~]# netstat -n
- Active Internet connections (w/o servers)
- Proto Recv-Q Send-Q Local Address Foreign Address State
- tcp 0 132 ::ffff:192.168.2.2:22 ::ffff:192.168.2.111:49913 ESTABLISHED
- tcp 0 0 ::ffff:192.168.2.2:22 ::ffff:192.168.2.111:56922 ESTABLISHED
- tcp 0 5396 ::ffff:192.168.2.2:22 ::ffff:192.168.2.111:56588 ESTABLISHED
- Active UNIX domain sockets (w/o servers)
- Proto RefCnt Flags Type State I-Node Path
- unix 2 [ ] DGRAM 1474 @/org/kernel/udev/udevd
- unix 2 [ ] DGRAM 7968 @/org/freedesktop/hal/udev_event
- unix 14 [ ] DGRAM 6838 /dev/log
- unix 2 [ ] DGRAM 50655
- unix 2 [ ] DGRAM 48147
- unix 2 [ ] DGRAM 48061
- unix 3 [ ] STREAM CONNECTED 9327 @/tmp/fam-root-
- unix 3 [ ] STREAM CONNECTED 9326
- unix 3 [ ] STREAM CONNECTED 9316 /var/run/dbus/system_bus_socket
- unix 3 [ ] STREAM CONNECTED 9315
- unix 3 [ ] STREAM CONNECTED 9127 /var/run/dbus/system_bus_socket
- unix 3 [ ] STREAM CONNECTED 9126
- unix 3 [ ] STREAM CONNECTED 9101 @/var/run/hald/dbus-EksVbyIVuK
- unix 3 [ ] STREAM CONNECTED 9100
- unix 3 [ ] STREAM CONNECTED 9092 /var/run/acpid.socket
- unix 3 [ ] STREAM CONNECTED 9091
- unix 3 [ ] STREAM CONNECTED 9082 @/var/run/hald/dbus-EksVbyIVuK
- unix 3 [ ] STREAM CONNECTED 9081
- unix 3 [ ] STREAM CONNECTED 8926 @/var/run/hald/dbus-EksVbyIVuK
- unix 3 [ ] STREAM CONNECTED 8924
- unix 3 [ ] STREAM CONNECTED 7963 @/var/run/hald/dbus-OlENpyyvWV
- unix 3 [ ] STREAM CONNECTED 7962
- unix 3 [ ] STREAM CONNECTED 7917 /var/run/dbus/system_bus_socket
- unix 3 [ ] STREAM CONNECTED 7916
- unix 3 [ ] STREAM CONNECTED 7911
- unix 3 [ ] STREAM CONNECTED 7910
- unix 2 [ ] DGRAM 7908
- unix 2 [ ] DGRAM 7681
- unix 2 [ ] DGRAM 7650
- unix 2 [ ] DGRAM 7615
- unix 2 [ ] DGRAM 7399
- unix 2 [ ] DGRAM 7345
- unix 2 [ ] DGRAM 7284
- unix 3 [ ] STREAM CONNECTED 7175
- unix 3 [ ] STREAM CONNECTED 7174
- unix 3 [ ] STREAM CONNECTED 7111
- unix 3 [ ] STREAM CONNECTED 7110
- unix 2 [ ] DGRAM 6849
- unix 2 [ ] DGRAM 6840
- unix 3 [ ] STREAM CONNECTED 6768
- unix 3 [ ] STREAM CONNECTED 6767
- [root@localhost ~]# netstat -r
- Kernel IP routing table
- Destination Gateway Genmask Flags MSS Window irtt Iface
- 192.168.2.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.2.1 0.0.0.0 UG 0 0 0 eth0
- [root@localhost ~]# netstat -l
- Active Internet connections (only servers)
- Proto Recv-Q Send-Q Local Address Foreign Address State
- tcp 0 0 *:sunrpc *:* LISTEN
- tcp 0 0 *:ssh *:* LISTEN
- getnameinfo failed
- getnameinfo failed
- getnameinfo failed
- getnameinfo failed
- getnameinfo failed
- getnameinfo failed
- udp 0 0 *:47133 *:*
- udp 0 0 *:mdns *:*
- udp 0 0 *:sunrpc *:*
- udp 0 0 *:41938 *:*
- udp 0 0 *:mdns *:*
- raw 0 0 *:icmp *:* 7
- raw 0 0 *:icmp *:* 7
- Active UNIX domain sockets (only servers)
- Proto RefCnt Flags Type State I-Node Path
- unix 2 [ ACC ] STREAM LISTENING 7453 /var/run/acpid.socket
- unix 2 [ ACC ] STREAM LISTENING 7726 /tmp/.font-unix/fs7100
- unix 2 [ ACC ] STREAM LISTENING 48069 /tmp/ssh-AEZfUj4473/agent.4473
- unix 2 [ ACC ] STREAM LISTENING 48155 /tmp/ssh-zzVwKC4508/agent.4508
- unix 2 [ ACC ] STREAM LISTENING 9324 @/tmp/fam-root-
- unix 2 [ ACC ] STREAM LISTENING 50663 /tmp/ssh-uUKGrr6628/agent.6628
- unix 2 [ ACC ] STREAM LISTENING 7691 /dev/gpmctl
- unix 2 [ ACC ] STREAM LISTENING 7914 /var/run/avahi-daemon/socket
- unix 2 [ ACC ] STREAM LISTENING 7960 @/var/run/hald/dbus-OlENpyyvWV
- unix 2 [ ACC ] STREAM LISTENING 7959 @/var/run/hald/dbus-EksVbyIVuK
- unix 2 [ ACC ] STREAM LISTENING 6841 /var/run/audispd_events
- unix 2 [ ACC ] STREAM LISTENING 7171 /var/run/dbus/system_bus_socket
- unix 2 [ ACC ] STREAM LISTENING 7312 /var/run/pcscd.comm
- [root@localhost ~]# netstat -t
- Active Internet connections (w/o servers)
- Proto Recv-Q Send-Q Local Address Foreign Address State
- getnameinfo failed
- getnameinfo failed
- tcp 0 132 [UNKNOWN]:ssh [UNKNOWN]:49913 ESTABLISHED
- getnameinfo failed
- getnameinfo failed
- tcp 0 0 [UNKNOWN]:ssh [UNKNOWN]:56922 ESTABLISHED
- getnameinfo failed
- getnameinfo failed
- tcp 0 5396 [UNKNOWN]:ssh [UNKNOWN]:56588 ESTABLISHED
- [root@localhost ~]# netstat -u
- Active Internet connections (w/o servers)
- Proto Recv-Q Send-Q Local Address Foreign Address State
- [root@localhost ~]# netstat -p
- Active Internet connections (w/o servers)
- Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
- getnameinfo failed
- getnameinfo failed
- tcp 0 148 [UNKNOWN]:ssh [UNKNOWN]:49913 ESTABLISHED 6628/2
- getnameinfo failed
- getnameinfo failed
- tcp 0 0 [UNKNOWN]:ssh [UNKNOWN]:56922 ESTABLISHED 4508/1
- getnameinfo failed
- getnameinfo failed
- tcp 0 5396 [UNKNOWN]:ssh [UNKNOWN]:56588 ESTABLISHED 4473/0
- Active UNIX domain sockets (w/o servers)
- Proto RefCnt Flags Type State I-Node PID/Program name Path
- unix 2 [ ] DGRAM 1474 579/udevd @/org/kernel/udev/udevd
- unix 2 [ ] DGRAM 7968 2978/hald @/org/freedesktop/hal/udev_event
- unix 14 [ ] DGRAM 6838 2474/syslogd /dev/log
- unix 2 [ ] DGRAM 50655 6628/2
- unix 2 [ ] DGRAM 48147 4508/1
- unix 2 [ ] DGRAM 48061 4473/0
- unix 3 [ ] STREAM CONNECTED 9327 3088/gam_server @/tmp/fam-root-
- unix 3 [ ] STREAM CONNECTED 9326 3086/python
- unix 3 [ ] STREAM CONNECTED 9316 2609/dbus-daemon /var/run/dbus/system_bus_socket
- unix 3 [ ] STREAM CONNECTED 9315 3086/python
- unix 3 [ ] STREAM CONNECTED 9127 2609/dbus-daemon /var/run/dbus/system_bus_socket
- unix 3 [ ] STREAM CONNECTED 9126 2978/hald
- unix 3 [ ] STREAM CONNECTED 9101 2978/hald @/var/run/hald/dbus-EksVbyIVuK
- unix 3 [ ] STREAM CONNECTED 9100 3001/hdc
- unix 3 [ ] STREAM CONNECTED 9092 2739/acpid /var/run/acpid.socket
- unix 3 [ ] STREAM CONNECTED 9091 2993/acpid.socket
- unix 3 [ ] STREAM CONNECTED 9082 2978/hald @/var/run/hald/dbus-EksVbyIVuK
- unix 3 [ ] STREAM CONNECTED 9081 2991/event0
- unix 3 [ ] STREAM CONNECTED 8926 2978/hald @/var/run/hald/dbus-EksVbyIVuK
- unix 3 [ ] STREAM CONNECTED 8924 2993/acpid.socket
- unix 3 [ ] STREAM CONNECTED 7963 2978/hald @/var/run/hald/dbus-OlENpyyvWV
- unix 3 [ ] STREAM CONNECTED 7962 2979/hald-runner
- unix 3 [ ] STREAM CONNECTED 7917 2609/dbus-daemon /var/run/dbus/system_bus_socket
- unix 3 [ ] STREAM CONNECTED 7916 2961/avahi-daemon:
- unix 3 [ ] STREAM CONNECTED 7911 2962/avahi-daemon:
- unix 3 [ ] STREAM CONNECTED 7910 2961/avahi-daemon:
- unix 2 [ ] DGRAM 7908 2961/avahi-daemon:
- unix 2 [ ] DGRAM 7681 2809/xinetd
- unix 2 [ ] DGRAM 7650 2841/crond
- unix 2 [ ] DGRAM 7615 2825/gpm
- unix 2 [ ] DGRAM 7399 2714/automount
- unix 2 [ ] DGRAM 7345 2693/hidd
- unix 2 [ ] DGRAM 7284 2658/pcscd
- unix 3 [ ] STREAM CONNECTED 7175 2609/dbus-daemon
- unix 3 [ ] STREAM CONNECTED 7174 2609/dbus-daemon
- unix 3 [ ] STREAM CONNECTED 7111 2580/rpc.idmapd
- unix 3 [ ] STREAM CONNECTED 7110 2580/rpc.idmapd
- unix 2 [ ] DGRAM 6849 2478/klogd
- unix 2 [ ] DGRAM 6840 2440/audispd
- unix 3 [ ] STREAM CONNECTED 6768 2438/auditd
- unix 3 [ ] STREAM CONNECTED 6767 2440/audispd
8.查看ARP缓存记录 arp -n
清空ARP缓存记录 arp -n|awk '/^[1-9]/{print "arp -d " $1}'|sh -x
- [root@localhost ~]# arp -n
- Address HWtype HWaddress Flags Mask Iface
- 192.168.2.111 ether 40:16:9F:F3:85:E7 C eth0
- 192.168.2.1 ether B0:48:7A:2E:98:D4 C eth0
- 192.168.2.222 ether 00:21:CC:4A:A8:60 C eth0
- [root@localhost ~]# arp -n|awk '/^[1-9]/{print "arp -d " $1}'|sh -x
- + arp -d 192.168.2.111
- + arp -d 192.168.2.1
- + arp -d 192.168.2.222
- [root@localhost ~]# arp -n
- Address HWtype HWaddress Flags Mask Iface
- 192.168.2.111 ether 40:16:9F:F3:85:E7 C eth0
- 192.168.2.1 ether B0:48:7A:2E:98:D4 C eth0
- 192.168.2.222 (incomplete) eth0
二、使用命令调整网络参数(临时生效)
1.修改网卡参数
ifconfig 接口名 ip地址 [netmask 子网掩码]
ifconfig 接口名 ip地址[/网络前缀]
ifconfig 接口名 down[/up]
ifconfig 接口名 hw ether 接口MAC地址
- [root@localhost ~]# ifconfig eth0 192.168.1.1 255.255.255.0
- [root@localhost ~]# ifconfig eth0 192.168.1.1/24
- [root@localhost ~]# ifconfig eth0 down
- [root@localhost ~]# ifconfig eth0 up
- [root@localhost ~]# ifdown eth0;ifup eth0
- [root@localhost ~]# ifconfig eth0 hw ether 00:11:22:33:44:55
2.设置路由记录
route add -net 网络地址/网络前缀 gw 下一跳IP
route add -host 主机IP gw 下一跳IP
route add default gw 下一跳IP
route del -net 网络地址/网络前缀 [gw 下一跳IP]
route del -host 主机IP [gw 下一跳IP]
route del default [gw 下一跳IP]
3.配置主机名 hostname 主机名
- [root@localhost ~]# hostname Mail_Server
- [root@localhost ~]# bash
- [root@Mail_Server ~]# hostname
- Mail_Server
4.配置静态arp arp -s 主机IP地址 主机MAC地址
- [root@localhost ~]# arp -n
- Address HWtype HWaddress Flags Mask Iface
- 192.168.2.111 ether 40:16:9F:F3:85:E7 C eth0
- [root@localhost ~]# arp -s 192.168.2.222 00:11:22:33:44:55
- [root@localhost ~]# arp -n
- Address HWtype HWaddress Flags Mask Iface
- 192.168.2.111 ether 40:16:9F:F3:85:E7 C eth0
- 192.168.2.222 ether 00:11:22:33:44:55 CM eth0
三、通过配置文件修改网络参数
1.网卡参数
/etc/sysconfig/network-scripts/ifcfg-接口名
DEVICE=接口名 ONBOOT=yes/no BOOTPROTO=static/dhcp
IPADDR=IP地址 NETMASK=子网掩码 GATEWAY=网关IP
- [root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
- # Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
- DEVICE=eth0
- BOOTPROTO=none
- ONBOOT=yes
- HWADDR=00:0c:29:75:78:09
- TYPE=Ethernet
- NETMASK=255.255.255.0
- IPADDR=192.168.2.2
- GATEWAY=192.168.2.1
2.修改主机名
/etc/sysconfig/network
NETWORKING=yes/no NETWORKING_IPV6=yes/no HOSTNAME=主机名
- [root@localhost ~]# cat /etc/sysconfig/network
- NETWORKING=yes
- NETWORKING_IPV6=no
- HOSTNAME=localhost.localdomain
3.配置DNS服务器IP
/etc/resolv.conf
nameserver DNS服务器IP
- [root@localhost ~]# cat /etc/resolv.conf
- nameserver 202.106.0.20
- nameserver 202.106.148.1
- search localdomain
4.配置本地的域名解析记录
/etc/hosts
IP地址 主机名
- [root@localhost ~]# cat /etc/hosts
- # Do not remove the following line, or various programs
- # that require network functionality will fail.
- 127.0.0.1 localhost.localdomain localhost
- ::1 localhost6.localdomain6 localhost6
四、使用DHCP动态配置主机地址
1.安装
rpm -ivh /media/Server/dhcp-版本信息
2.修改主配置文件
cp /usr/share/doc/dhcp-版本/dhcpd.conf.sample /etc/dhcpd.conf
vi /etc/dhcpd.conf
3.重要配置项
option routers 网关IP;
option sub-netmask 子网掩码;
option domain-name-servers 首选DNS,备用DNS;
rang 开始IP 结束IP;
default-lease-time 默认租约时间;
max-lease-time 最大租约时间;
hardware ethernet 主机MAC地址;
fixed-address 保留IP地址;
4.启动服务
service dhcpd start
- [root@localhost ~]# mount /dev/cdrom /media/
- mount: block device /dev/cdrom is write-protected, mounting read-only
- [root@localhost ~]# cd /media/Server/
- [root@localhost Server]# rpm -ivh dhcp-*.rpm
- warning: dhcp-3.0.5-18.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
- Preparing... ########################################### [100%]
- 1:dhcp ########################################### [ 50%]
- 2:dhcp-devel ########################################### [100%]
- [root@localhost Server]# cd
- [root@localhost ~]# cat /etc/dhcpd.conf
- #
- # DHCP Server Configuration file.
- # see /usr/share/doc/dhcp*/dhcpd.conf.sample
- #[root@localhost ~]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.cnf
- cp:是否覆盖“/etc/dhcpd.conf”? y
- [root@localhost ~]# vi /etc/dhcpd.conf
- 1 ddns-update-style interim;
- 2 ignore client-updates;
- 3
- 4 subnet 192.168.2.0 netmask 255.255.255.0 {
- 5
- 6 # --- default gateway
- 7 option routers 192.168.2.1;
- 8 option subnet-mask 255.255.255.0;
- 9
- 1 ddns-update-style interim;
- 2 ignore client-updates;
- 3
- 4 subnet 192.168.2.0 netmask 255.255.255.0 {
- 5
- 6 # --- default gateway
- 7 option routers 192.168.2.1;
- 8 option subnet-mask 255.255.255.0;
- 9
- 10 option nis-domain "domain.org";
- 11 option domain-name "domain.org";
- 12 option domain-name-servers 202.106.0.20,202.106.148.1;
- 13
- 14 option time-offset -18000; # Eastern Standard Time
- 15 # option ntp-servers 192.168.1.1;
- 16 # option netbios-name-servers 192.168.1.1;
- 17 # --- Selects point-to-point node (default is hybrid). Don't change this
- unless
- 18 # -- you understand Netbios very well
- 19 # option netbios-node-type 2;
- 20
- 21 range dynamic-bootp 192.168.2.128 192.168.2.254;
- 22 default-lease-time 21600;
- "/etc/dhcpd.conf" 31L, 872C written
- [root@localhost ~]# service dhcpd restart
- 启动 dhcpd: [确定]
- [root@localhost ~]# chkconfig dhcpd on
5.设置在哪块网卡提供DHCP服务
/etc/sysconfig/dhcpd
DHCPARGS=”接口名”
6.租期数据库文件
/var/lib/dhcpd/dhcpd.lease
- [root@localhost ~]# cat /etc/sysconfig/dhcpd
- # Command line options here
- DHCPDARGS="eth0"
- [root@localhost ~]# cat /var/lib/dhcpd/dhcpd.leases
- # All times in this file are in UTC (GMT), not your local timezone. This is
- # not a bug, so please don't ask about it. There is no portable way to
- # store leases in the local timezone, so please don't request this as a
- # feature. If this is inconvenient or confusing to you, we sincerely
- # apologize. Seriously, though - don't ask.
- # The format of this file is documented in the dhcpd.leases(5) manual page.
- # This lease file was written by isc-dhcp-V3.0.5-RedHat
- lease 192.168.2.254 {
- starts 5 2012/04/06 10:15:22;
- ends 5 2012/04/06 16:15:22;
- tstp 5 2012/04/06 16:15:22;
- binding state active;
- next binding state free;
- hardware ethernet 00:0c:29:63:46:4f;
- uid "\001\000\014)cFO";
- client-hostname "benet-5";
- }