通过配置文件配置路由:
vim /etc/sysconfig/network-script/route-eth0
方法一:
10.0.0.0/24 via 192.168.57.2
保存,退出。service network restart
[root@unp network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0 192.168.57.2 255.255.255.0 UG 0 0 0 eth0
192.168.57.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
0.0.0.0 192.168.57.1 0.0.0.0 UG 0 0 0 eth0
方法二:
ADDRESS0=10.0.0.0
NETMASK0=255.255.255.0
GATEWAY0=192.168.57.2
ADDRESS1=10.1.1.1
NETMASK1=255.255.255.255
GATEWAY1=192.168.57.3
保存,退出。service network restart
[root@unp ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.1.1.1 192.168.57.3 255.255.255.255 UGH 0 0 0 eth0
10.0.0.0 192.168.57.2 255.255.255.0 UG 0 0 0 eth0
192.168.57.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
0.0.0.0 192.168.57.1 0.0.0.0 UG 0 0 0 eth0
配置dns:
vim /etc/resolv.conf
[root@unp ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 8.8.8.8
arp:查询arp表:
arp -n
[root@unp ~]# arp -n
Address HWtype HWaddress Flags Mask Iface
192.168.57.1 ether 00:00:0c:07:ac:00 C eth0
192.168.57.230 ether 00:0c:29:4e:00:f7 C eth0
192.168.57.63 ether 1c:6f:65:0a:20:a1 C eth0
arp –s 192.168.57.5 00:00:22:00:44:55 静态绑定mac地址
[root@unp ~]# arp -s 192.168.57.5 00:00:22:00:44:55
[root@unp ~]# arp -n
Address HWtype HWaddress Flags Mask Iface
192.168.57.5 ether 00:00:22:00:44:55 CM eth0
192.168.57.1 ether 00:00:0c:07:ac:00 C eth0
192.168.57.230 ether 00:0c:29:4e:00:f7 C eth0
192.168.57.63 ether 1c:6f:65:0a:20:a1 C eth0
arp –d 192.168.57.5
[root@unp ~]# arp -d 192.168.57.5
[root@unp ~]# arp -n
Address HWtype HWaddress Flags Mask Iface
192.168.57.5 (incomplete) eth0
192.168.57.1 ether 00:00:0c:07:ac:00 C eth0
192.168.57.230 ether 00:0c:29:4e:00:f7 C eth0
192.168.57.63 ether 1c:6f:65:0a:20:a1 C eth0
ip neigh: 替代arp的工具
[root@unp ~]# ip neigh show
192.168.57.1 dev eth0 lladdr 00:00:0c:07:ac:00 DELAY
192.168.57.63 dev eth0 lladdr 1c:6f:65:0a:20:a1 STALE
ip neigh add 192.168.57.6 lladdr 11:22:33:44:55:66 nud permanent dev eth0 绑定MAC地址
[root@unp ~]# ip neigh add 192.168.57.6 lladdr 11:22:33:44:55:66 nud permanent dev eth0
[root@unp ~]# ip neigh show
192.168.57.6 dev eth0 lladdr 11:22:33:44:55:66 PERMANENT
192.168.57.1 dev eth0 lladdr 00:00:0c:07:ac:00 REACHABLE
192.168.57.39 dev eth0 lladdr 00:50:56:9f:6e:b6 STALE
192.168.57.63 dev eth0 lladdr 1c:6f:65:0a:20:a1 STALE
ip neigh del 192.168.57.6 lladdr 11:22:33:44:55:66 nud permanent dev eth0 删除绑定的MAC地址
root@unp ~]# ip neigh del 192.168.57.6 lladdr 11:22:33:44:55:66 nud permanent dev eth0
[root@unp ~]# ip neigh show
192.168.57.1 dev eth0 lladdr 00:00:0c:07:ac:00 REACHABLE
192.168.57.39 dev eth0 lladdr 00:50:56:9f:6e:b6 STALE
192.168.57.63 dev eth0 lladdr 1c:6f:65:0a:20:a1 STALE
netstat: 打印网络连接、路由表、接口状态
-t : tcp连接
-u: udp连接
-l : 仅显示侦听的sockets(缺省有些选项)
-n: 数字格式显示
-p: 显示每个socket的PID
-a: 显示所有侦听和不侦听的socket
netstat –r == ip route list
netstat –i == ip –s link
[root@unp ~]# netstat -i
Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1400 0 451374 2 0 0 159066 0 0 0 BMRU
lo 16436 0 374392 0 0 0 374392 0 0 0 LRU
[root@unp ~]# ip -s link
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
RX: bytes packets errors dropped overrun mcast
22463520 374392 0 0 0 0
TX: bytes packets errors dropped carrier collsns
22463520 374392 0 0 0 0
2: eth0: mtu 1400 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 00:50:56:9f:22:36 brd ff:ff:ff:ff:ff:ff
alias mynet
RX: bytes packets errors dropped overrun mcast
92986751 451401 2 0 0 0
TX: bytes packets errors dropped carrier collsns
38805032 159084 0 0 0 0
netstat –tulnap
[root@unp ~]# netstat -tulnap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:46283 0.0.0.0:* LISTEN 1464/rpc.statd
tcp 0 0 0.0.0.0:8140 0.0.0.0:* LISTEN 1766/ruby
tcp 0 0 0.0.0.0:3790 0.0.0.0:* LISTEN 2189/nginx
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1420/rpcbind
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1711/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1569/cupsd
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 15781/mysqld
tcp 0 0 192.168.57.23:22 192.168.57.63:23845 ESTABLISHED 2058/sshd
tcp 0 0 192.168.57.23:22 10.241.19.12:60567 ESTABLISHED 23130/sshd
tcp 0 0 192.168.57.23:22 10.241.19.12:60514 ESTABLISHED 21897/sshd
tcp 0 0 192.168.57.23:22 10.241.19.12:60568 ESTABLISHED 23151/sshd
tcp 0 52 192.168.57.23:22 10.241.19.12:60848 ESTABLISHED 25393/sshd
tcp 0 0 192.168.57.23:22 10.241.19.12:60512 ESTABLISHED 21876/sshd
tcp 0 0 192.168.57.23:22 10.241.19.12:60849 ESTABLISHED 25414/sshd
tcp 0 0 :::111 :::* LISTEN 1420/rpcbind
tcp 0 0 :::38449 :::* LISTEN 1464/rpc.statd
tcp 0 0 :::22 :::* LISTEN 1711/sshd
tcp 0 0 :::23 :::* LISTEN 1719/xinetd
tcp 0 0 ::1:631 :::* LISTEN 1569/cupsd
udp 0 0 0.0.0.0:747 0.0.0.0:* 1420/rpcbind
udp 0 0 0.0.0.0:111 0.0.0.0:* 1420/rpcbind
udp 0 0 0.0.0.0:631 0.0.0.0:* 1569/cupsd
udp 0 0 192.168.57.23:123 0.0.0.0:* 1727/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 1727/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 1727/ntpd
udp 0 0 0.0.0.0:514 0.0.0.0:* 1377/rsyslogd
udp 0 0 0.0.0.0:792 0.0.0.0:* 1464/rpc.statd
udp 0 0 0.0.0.0:47770 0.0.0.0:* 1464/rpc.statd
udp 0 0 :::747 :::* 1420/rpcbind
udp 0 0 :::111 :::* 1420/rpcbind
udp 0 0 fe80::250:56ff:fe9f:2236:123 :::* 1727/ntpd
udp 0 0 ::1:123 :::* 1727/ntpd
udp 0 0 :::123 :::* 1727/ntpd
udp 0 0 :::514 :::* 1377/rsyslogd
udp 0 0 :::35147 :::* 1464/rpc.statd
Proto: socket使用的协议,可以是tcp,udp,raw
Recv-Q: The count of bytes not copied by the user program connected to this socket.
Send-Q:
The count of bytes not acknowledged by the remote host.
Local Address: 本机地址:端口号
Foreign Address: 远程地址:端口号
State: Socket状态
ESTABLISHED: 连接已建立
SYN_SENT: 尝试建立连接,发送syn
SYN_RECV: 接收到syn请求
FIN_WAIT1: socket关闭,连接被关闭
FIN_WAIT2: 连接关闭,socket等待关闭
TIME_WAIT: 连接关闭之后,socket处于等待状态
CLOSED: socket不被使用
CLOSED_WAIT: 远端已经关闭,等待socket关闭
LAST_ACK: 远端已经关闭,sock也已关闭
LISTEN: 侦听状态
CLOSING: Both sockets都已关闭
UNKNOWN: 未知的socket状态
PID/Program: socket所使用的进程ID和进程名称