網絡屬性配置(二)
本文接上篇。。。
ip address -protocol address management.
ip address add -add new protocol address
ip addr add IFADDR
label NAME :為額外添加的地址指明接口別名
[broadcast ADDRESS]: 廣播地址;會根據IP和ENTMASK自動計算得到;
[scope SCOPE_VALUE];
global : 全局可用;
link : 接口可用;
host : 僅本機可用;
ip address add -delete - protocol address
ip addr delete IFADDR dev IFACE
ip address add -show - look at protocol addresses
[IFACE]:僅顯示指定接口的地址;
ip address add -flush -flush protocol addresses
ip addr flush dev IFACE
ip route -routing table management
ip route add -add new route
ip route change -change route
ip route replace - change or add new one
ip route add TYPE PREFIX via GW[dev IFACE] [src SOURCE_IP]
示例:
#ip route add 192.168.0.0/24 via 10.0.0.0.1 dev eth1 src 10.0.20.100
#ip route add default bia GW
ip route delete -delete route
示例:
# ip route delete 192.168.1.0/24
ip route show -list routes
TYPE PRIFIX
ip route flush -flush routing tables
TYPE PRIFIX
ip route get-get a single route
ip route get TYPE PRIFIX
示例ip route get 192.168.0.0/24
ss命令:
ss [option] [FILTER]
選項:
-t: TCP協議的相關連接
-u:UDP相關的連接
-w: raw socket 相關的連接
-l :監聽狀態的連接
-a:所有狀態的連接
-n:數字格式
-p: 相關的程序及PID
-e:擴展格式
-m:內存用量
-o:計時器信息
TCP的常見狀態:
TCP FSM:
LISTEN: 監聽
ESTABLISEHD:建立的連接
FIN _WAIT_1:
FIN_WAIT_2:
SYN_SENT:
SYN_RECV :
CLOSED:
EXPRESSION:
dport= 目標端口
sport= 原端口
示例:‘(dport = :22 or sport = :22 )'
~]# ss -tan '( dport = :22 or sport = :22 )'
~]# ss -tan state ESTABLISHED
配置文件:
IP/NATMASK/GW/DNS等屬性的配置文件:
IFACE:接口名稱;
路由的相關配置文件:
/etc/sysconfig/network-scripts/ifcfg-IFACE
配置文件 /etc/sysconfig/networkj-scripts/route-IFACE通過大量參數來定義接口的屬性;
也可通過vim等文本來編輯器直接修改。
也可以使用專用的命令的進行修改(Centos 6:system-config-network(setup),centos7:nmtui)
ifcfg-IFACE配置文件參數:
DEVICE:此配置文件對應的設備的名稱:
ONBOOT: 系統引導過程中,是否激活此接口;
UUID:此設備的唯一標志
IPV6INIT: 是否初始化IPv6;
BOOTPROTO:激活此接口是使用什么協議來配置接口屬性,常用的有dhcp,bootp,static,none;
TYPE:接口類型,常見的有Ethernet,Bridge;
DNS1:第一DNS服務器指向;
DNS2:備用DNS服務器指向;
DOMAIN:DNS搜索域;
GATEWAY: 默認網關;
USERCTL:是否允許普通用戶控制此設備;
PEERNDS: 如果BOOTPROTO的值為“dhcp", 是否允許dhcp server 分配的dns
服務器指向覆蓋本地手動指定的DNS服務器指向;默認為允許;
HWADDR:設備的MAC地址;
NM_CONTROLLED:是否使用NetworkManager服務來控制接口;
網絡服務:
network
NetworkManager
管理網絡服務:
Centos6: service SERVICE {start | stop | restart | status}
Centos7:ossystemctl {start | stop | restart | status } SERVICE [ .service]
配置文件修改之后,如果要生效,需要重啟網絡服務;
# service network restart
Centos6:service network restart
Centos7: # systemctl restart network.service
用到非默認網關路由:/etc/sysconfig/network-scripts/route-IFACE
支持兩種配置方式,但不可混用;
(1)每行一個路由條目:
TARGET via GW
(2)沒三行一個路由條目;
ADDRESS#=TARGET
NETMASK#=MASK
GATEWAY#=NEXTHOP
給接口配置多個地址:
ip addr之外,ifconfig或配置文件都可以;
(1)ifconfig IFACE_LABEL IPADDR/NETMASK
IFACE_LABEL : eth0:0, eth0:1,.....
(2)為別名添加配置文件:
DEVICE=IFACE_LABEL
BOOTPROTO : 網上別名不支持動態獲取地址;
static, none
nmcli命令:Centos7 專用
nmcli :[OPTIONS] OBJET{ COMMAND | help }
cevice - show and manage network interfaces
COMMAND : = { status | show |connect | delete | wifi |wimax }
connection - start, stop, and manage network connections
COMMAND : = { show | up | down | add | edit | modify | delete | reload | load }
modify [ id | uuid | path ] <ID> [+ | -]<setting>.<property><value>
如何修改IP地址等屬性:
# nmcli conn modify IFACE [+ | - ]setting.property value
ipv4,address
ipv4.gateway
ipv4.dns1
ipv4.method
manual