标签:linux网络配置
Linux网络配置
(CentOS6 CentOS7)
篇一
ifconfig 命令用来查看和配置网络设备.网络环境发生改变可通过此命令对网络进行相应的配置.
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE="eth0" 网卡接口 BOOTPROTO="dhcp" -dhcp动态协议 -static:静态协议 -bootp协议 HWADDR="00:0C:29:AB:DC:D7" 网卡MAC地址 NM_CONTROLLED="yes" 此网卡是否接受NetworkManager控制;CentOS6建议为“no” ONBOOT="yes" 系统启动时是否自动加载 GATEWAY="192.168.1.0" 网卡网关地址 TYPE="Ethernet" 网卡类型 IPADDR=192.168.1.107 网卡IP地址(静态协议需要设置) NETMASK=255.255.255.0 网卡网络地址(静态协议需要设置) BROADCAST=192.168.1.255 网卡广播地址 UUID="c05f7c37-2d21-4db7-be93-8a0dd2f661ec" [root@localhost ~]# ifdown eth0 关闭网络 [root@localhost ~]# ifup eth0 启动网络 [root@localhost ~]# service network stop 关闭网络服务 [root@localhost ~]# service network start 启动网络服务 [root@localhost ~]# service network restart 重启网络服务
route命令用于显示和操作IP路由表(show / manipulate the IP routing table)
route add [-net|-host] target [netmask Nm] [gw Gw] [[dev] If]
[root@localhost ~]# route add -host 192.168.1.107 gw 172.16.0.1 dev eth1
route del [-net|-host] target [gw Gw] [netmask Nm] [[dev] If]
[root@localhost ~]# route del -host 192.168.1.106 [root@localhost ~]# route del -net 192.168.0.0 netmask 255.255.255.0
route -n 查看路由表
{DNS服务器指定}
[root@localhost ~]# vi /etc/resolv.conf # Generated by NetworkManager nameserver 10.10.10.1 nameserver 192.168.1.1
netstat-Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships(显示网络连接,路由表、接口统计,伪装的连接,和组播成员)
[root@localhost ~]# netstat -t (tcp协议连接) Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 52 192.168.1.105:ssh 192.168.1.102:55765 ESTABLISHED [root@localhost ~]# netstat -u (udp协议的链接) Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State [root@localhost ~]# netstat -r (显示路由表,类似于route或ip route show) Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 192.168.1.0 * 255.255.255.0 U 0 0 0 eth1 default 192.168.1.1 0.0.0.0 UG 0 0 0 eth1
-l:监听状态的连接
-a:所有状态的连接
-p:连接相关的进程
-n:数字格式显示
ss,用于取代netstat (优势在于udp) 摘要
-t:tcp协议的连接
-u:udp协议的链接
-l:监听状态的连接
-a:所有状态的连接
-e:显示扩展信息
-m:显示套接连接使用的内存信息
-p:进程及UDP
-n:数字格式显示
-o state (established)
篇二
配置Linux网络属性:ip命令
[root@localhost ~]# ip -s link show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 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 1312 24 0 0 0 0 TX: bytes packets errors dropped carrier collsns 1312 24 0 0 0 0 2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:35:de:4e brd ff:ff:ff:ff:ff:ff RX: bytes packets errors dropped overrun mcast 98128879 139122 0 0 0 0 TX: bytes packets errors dropped carrier collsns 8388577 63333 0 0 0 0
[root@localhost ~]# ip address [add|del] [IP参数] [dev 设备名] [相关参数] 参数: show :单纯的显示出设备的 IP 信息; add|del :进行相关参数的增加 (add) 或删除 (del) 设定,主要有: IP 参数 :主要就是网域的设定,例如 192.168.100.100/24 之类的设定;
[root@localhost ~]# ip addr add 4.4.4.4/32 dev eth1 label eth1:zhong [root@localhost ~]# ip addr show eth1 2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:35:de:4e brd ff:ff:ff:ff:ff:ff inet 192.168.1.105/24 brd 192.168.1.255 scope global eth1 inet 2.2.2.2/24 scope global eth1 inet 3.3.3.3/32 scope global eth1:1 inet 4.4.4.4/32 scope global eth1:zhong inet6 fe80::20c:29ff:fe35:de4e/64 scope link valid_lft forever preferred_lft forever
[root@localhost ~]# ip route show <==单纯的显示出路由设定 [root@localhost ~]# ip route [add|del] [IP或网域] [via gateway] [dev 设备] [root@localhost ~]# ip route show 2.2.2.0/24 dev eth1 proto kernel scope link src 2.2.2.2 192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.105 metric 1 default via 192.168.1.1 dev eth1 proto static
增加可以通往外部的路由,需透过 route
增加预设路由ip route add default via[IP或网域] [dev 设备]
删除路由ip route del [IP或网域]
"外卖"
/etc/sysconfig/network-scripts/route-IFACE 两种风格: (1) TARGET via GW (2) 每三行定义一条路由 ADDRESS#=TARGET NETMASK#=mask GATEWAY#=GW 给网卡配置多地址: ifconfig: ifconfig IFACE_ALIAS ip ip addr add 配置文件: ifcfg-IFACE_ALIAS DEVICE=IFACE_ALIAS 注意:网关别名不能使用dhcp协议引导; Linux网络属性配置的tui(text user interface): system-config-network-tui 也可以使用setup找到; 注意:记得重启网络服务方能生效; 配置当前主机的主机名: hostname [HOSTNAME] /etc/sysconfig/network HOSTNAME= 网络接口识别并命名相关的udev配置文件: /etc/udev/rules.d/70-persistent-net.rules 卸载网卡驱动: modprobe -r e1000 装载网卡驱动: modprobe e1000
篇三 (CentOS7)
地址配置工具:nmcli
本文出自 “Hotel California” 博客,请务必保留此出处http://zhongshixun.blog.51cto.com/10314910/1691252
标签:linux网络配置
原文地址:http://zhongshixun.blog.51cto.com/10314910/1691252