1、图形化网络配置工具
(1)CentOS6下图形化网络配置工具
1)system-config-network(或system-config-network-tui)
2)setup
(2)cnetos7下图形化网络配置管理工具
1)nm-connection-editor(需要在图形化界面终端中使用)
2)nmtui
3)nmcli
2、ifconfig命令的使用(centos7上默认没有此命令,需要安装net-tools包)
(1)查看主机ip
1)ifconfig #查看所有接口网络配置信息
2)ifconfig interface#查看指定接口的网络配置信息
(2)启用或者停用网卡
1)关闭网卡:ifconfig eth0down
2)启用网卡:ifconfig eth0up
(3)修改配置IP地址
1)设置修改IP地址:ifconfig eth1 ipaddress/netmask(临时生效)
[root@linuxidc ~]$ifconfigeth0 #查看eth0IP地址
eth0 Link encap:Ethernet HWaddr 00:0C:29:D3:7B:9B
inet addr:172.16.254.250 Bcast:172.16.255.255 Mask:255.255.0.0
inet6 addr:fe80::20c:29ff:fed3:7b9b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:28487 errors:0 dropped:0overruns:0 frame:0
TX packets:157 errors:0 dropped:0overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2833396 (2.7 MiB) TX bytes:25918 (25.3 KiB)
[root@linuxidc ~]$ifconfigeth0 192.168.1.2/24 #修改eth0IP地址
(4)配置网卡别名:ifconfig eth0:0 ipaddress/netmaskup
[root@linuxidc ~]# ifconfigeth0:0 6.6.6.6/24
[root@linuxidc ~]# ifconfigeth0:0
eth0:0:flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1280
inet 6.6.6.6 netmask 255.255.255.0 broadcast 6.6.6.255
ether 00:0c:29:ed:0f:11 txqueuelen 100 (Ethernet)
3、路由管理命令router
(1)查看路由:route –n
[root@linuxidc ~]$route –n #查看路由表
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.80.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1
172.16.0.0 0.0.0.0 255.255.0.0 U 1 0 0 eth0
0.0.0.0 172.16.0.1 0.0.0.0 UG 0 0 0 eth0
(2)添加与删除
添加路由:route add[-net|-host] target [netmask Nm] [gwGw] [[dev] If]
删除路由:route del[-net|-host] target [gwGw] [netmask Nm] [[dev] If]
(3)配置路由案例:
Linux配置路由拓扑图
1)Linux1的配置
[root@linux1 ~]# echo 1> /proc/sys/net/ipv4/ip_forward #开启主机路由转发功能
[root@linux1 ~]# route add -net192.168.2.0/30 gw 192.168.1.2
[root@linux1 ~]# route add -net10.0.0.0/24 gw 192.168.1.2
[root@linux1 ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default server.magelinu 0.0.0.0 UG 100 0 0 eth2
10.0.0.0 192.168.1.2 255.255.255.0 UG 0 0 0 eth0
172.16.0.0 0.0.0.0 255.255.0.0 U 100 0 0 eth2
192.168.1.0 0.0.0.0 255.255.255.252 U 100 0 0 eth0
192.168.2.0 192.168.1.2 255.255.255.252 UG 0 0
2)linux2的配置
[root@linux2 ~]# echo 1> /proc/sys/net/ipv4/ip_forward
[root@linux2 ~]# route add -net172.16.1.0/24 gw 192.168.1.1
[root@linux2 ~]# route add -net10.0.0.0/24 gw 192.168.2.2
[root@linux2 ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0 192.168.2.2 255.255.255.0 UG 0 0 0 eth1
172.16.1.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 100 0 0 eth0
192.168.2.0 0.0.0.0 255.255.255.252 U 100 0
3)linux3配置
[root@linux3 ~] echo 1> /proc/sys/net/ipv4/ip_forward
[root@linux3 ~]$route add -net192.168.1.0/30 gw 192.168.2.1
[root@linux3 ~]$route add -net172.16.1.0/30 gw 192.168.2.1
[root@linux3 ~]$route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth1
172.16.1.0 192.168.2.1 255.255.255.252 UG 0 0 0 eth0
192.168.1.0 192.168.2.1 255.255.255.252 UG 0 0 0 eth0
192.168.2.0 0.0.0.0 255.255.255.252 U 100 0 0 eth0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0
4)linux4的配置(linux4当做客户机时不用配置路由,将网关指向下一跳即可,此处为linux1的eth0接口地址)
[root@linux1 ~]$ echo 1> /proc/sys/net/ipv4/ip_forward
[root@linux1 ~]$route add –net192.168.1.0/30 gw 172.16.1.1
[root@linux1 ~]$ route add –net192.168.2.0/30 gw 172.16.1.1
[root@linux1 ~]$ route add –net10.0.0.0/24 gw 172.16.1.1
[root@linux1 ~]$route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 172.16.1.1 255.255.255.252 UG 0 0 0 eth0
192.168.1.0 172.16.1.1 255.255.255.252 UG 0 0 0 eth0
10.0.0.0 172.16.1.1 255.255.255.0 UG 0 0 0 eth0
172.16.1.0 * 255.255.255.0 U 1 0 0 eth0
default 172.16.1.1 0.0.0.0 UG 0 0 0 eth0
5)linux5的配置(Linux5当做网关使用时不用配置路由,将网关指向下一跳地址即可,此处为linux3的eth1接口地址即可)
[root@linux5 ~]$echo 1> /proc/sys/net/ipv4/ip_forward
[root@linux5 ~]$ route add -net192.168.2.0/30 gw 10.0.0.254
[root@linux5 ~]$ route add -net192.168.1.0/30 gw 10.0.0.254
[root@linux5 ~]$ route add -net172.16.1.0/24 gw 10.0.0.254
[root@linux5 ~]$route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 10.0.0.1 255.255.255.252 UG 0 0 0 eth1
192.168.1.0 10.0.0.1 255.255.255.252 UG 0 0 0 eth1
10.0.0.0 * 255.255.255.0 U 1 0 0 eth1
172.16.1.0 10.0.0.1 255.255.255.0 UG 0 0 0 eth1
172.16.0.0 * 255.255.0.0 U 1 0 0 eth0
default server.magelinu 0.0.0.0 UG 0 0 0 eth0
(4)Linux主机配置动态路由
1)需要安装包quagga
[root@linux5 ~]$yum installquagga
2)配置:
[root@linux5 ~]$cd /etc/quagga/
[root@linux5 quagga]$cpospfd.conf.sample ospfd.conf #修改配置文件,时配置文件生效
[root@linux5quagga]$/etc/init.d/ospfd start #启动ospf路由协议
[root@linux5 ~]$vtysh #进入配置动态路由
Hello, this is Quagga (version0.99.15).
Copyright 1996-2005 KunihiroIshiguro, et al.
linux5#
linux5#
linux5# enable
% Unknown command.
linux5# configure terminal
linux5(config)#
4、网络管理命令ip
(1)使用IP命令管理网卡
1)关闭网卡:ip link setdev eth0 down
2)启用网卡:ip link setdev eth0 up
(2)使用ip命令配置网络
1)用法:ip addr{ add |del } IFADDR dev STRING
2)常用选项:
[label LABEL]:添加地址时指明网卡别名
[scope {global|link|host}]:指明作用域
global: 全局可用
link: 仅链接可用
host: 本机可用
[broadcast ADDRESS]:指明广播地址
[root@linuxidc ~]# ip addr add6.6.6.6/24 dev eth0 label eth0:0 #添加IP地址指定标签
[root@linuxidc ~]# ip addr #查看网卡配置信息
……
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP>mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:ed:0f:11 brdff:ff:ff:ff:ff:ff
inet 172.16.250.102/16 brd 172.16.255.255scope global dynamic eth0
valid_lft 85913sec preferred_lft85913sec
inet6.6.6.6/24 scope global eth0:0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:feed:f11/64 scope link
valid_lft forever preferred_lft forever
[root@linuxidc ~]# ip addr del6.6.6.6/24 dev eth0 label eth0:0 #删除地址
3)修改网卡MTU(最大传输单元)
命令:ip link set devIFACE mtu 1500
[root@linuxidc ~]# ip link setdev eth0 mtu 1000 #改变传输单元
[root@linuxidc ~]# ip -s -s linkls eth0 #查看网卡1的详细信息
2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu1000 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:ed:0f:11 brdff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
13836570 145845 0 0 0 0
RX errors: length crc frame fifo missed
0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
218116 1694 0 0 0 0
TX errors: aborted fifo window heartbeat
0 0 0 0
3)改变设备队列传输长度:ip link set dev IFACE txqueuelen
[root@linuxidc ~]# ip link setdev eth0 txqueuelen 100 #改变网卡队列传输长度
[root@linuxidc ~]# ip -s -s linkls eth0 #查看修改后网卡最大传输单元
2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1000 qdisc pfifo_fast state UP modeDEFAULT qlen 100
(3)使用ip命令配置路由
1)添加路由:ip route addTARGET via GW dev IFACE srcSOURCE_IP
2)删除路由:ip routedelete
3)查看路由:ip route(或ip route (show |list))
4)清空路由表:ip routeflush[dev IFACE] [via PREFIX]
[root@linuxidc ~]# ip route add10.0.0.0/24 via 172.16.0.1 #添加路由
[root@linuxidc ~]# ip route #查看路由表
default via 172.16.0.1 deveth0 proto static metric 100
10.0.0.0/24 via 172.16.0.1 deveth0
172.16.0.0/16 dev eth0 proto kernel scope link src172.16.250.102 metric 100
192.168.122.0/24 devvirbr0 proto kernel scope link src 192.168.122.1
[root@linuxidc ~]# ip routeflush dev eth0 #清空路由表
5、网络状态查看命令netstat命令使用
(1)用法:netstat[--tcp|-t] [--udp|-u] [--raw|-w][--listening|-l] [--all|-a] [--numeric|-n] [--extend|-e[--extend|-e]][--program|-p]
(2)参数:
1)-t: tcp协议相关
2)-u: udp协议相关
3)-w: raw socket相关
4)-l: 处于监听状态
5)-a: 所有状态
6)-n: 以数字显示IP和端口;
7)-e:扩展格式
8)-p: 显示相关进程及PID
(3)组合使用
[root@linuxidc ~]# netstat–tan #以数字形式显示tcp协议相关的状态
Active Internet connections(servers and established)
Proto Recv-Q Send-Q LocalAddress Foreign Address State
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
[root@linuxidc ~]# netstat–tnl #以数字形式显示所有处于监听状态的tcp协议状态
Active Internet connections(only servers)
Proto Recv-Q Send-Q LocalAddress Foreign Address State
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
[root@linuxidc ~]# netstat -lntp
Active Internet connections(only servers)
Proto Recv-Q Send-Q LocalAddress Foreign Address State PID/Program name
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1826/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1143/sshd
(4)显示路由表:netstat{--route|-r} [--numeric|-n]
[root@linuxidc ~]# netstat–rn #以数字的形式显示网卡信息(不加-n会尝试解析成主机名)
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 172.16.0.1 0.0.0.0 UG 0 0 0 eth0
172.16.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
(5)显示接口统计数据:netstat{--interfaces|-I|-i}[iface] [--all|-a] [--extend|-e] [--program|-p] [--numeric|-n]
[root@linuxidc ~]# netstat–i #查看所有网卡信息
Kernel Interface table
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1000 158203 0 0 0 2050 0 0 0 BMRU