回顧:計算機網絡基礎、Linux網絡屬性配置服務器
- TCP/IP協議棧:物理層、互聯網層、傳輸層、應用層
- 互聯網層:IP
- 傳輸層:TCP、UDP
- 應用層:http、https、ftp、ldap...
- 數據鏈路層:以太網幀
- 互聯網層:IP報文
- 以太網幀:MTU(1500)
- Linux網絡屬性配置:命令、配置文件
Linux網絡屬性配置(2)網絡
- ifcfg命令家族:ifconfig,route,netstat
- ifconfig命令:接口及地址查看和管理
- ifconfig [interface]
- ifconfig interface [aftype] options | address...
- ifconfig IFACE IP/MASK [up]
- ifconfig IFACE IP netmask NETMASK
- options:
- 注意:當即送往內核中的TCP/IP協議棧,並生效;
- 管理IPV6地址
- add addr/prefixlen
- del addr/prefixlen
- route命令:路由查看及管理
- 路由條目類型
- 主機路由:目標地址爲單個IP
- 網絡路由:目標地址爲IP網絡
- 默認路由:目標地址爲任意主機,0.0.0.0/0.0.0.0
- 查看路由條目:route -n
- 添加路由條目:route add [-net | -host] Target [netmask Nm] [gw Gw] [[dev] If]
- -net:網絡路由
- -host:主機路由
- netmask:掩碼
- gw:網關
- dev:哪一個網卡
- route add -net 10.0.0.0/8 gw 192.168.10.1 dev eth1
- 刪除路由條目:route del [-net | -host] Target [netmask Nm] [gw Gw] [[dev] If]
- netstat命令:
- 顯示路由表:netstat -rn
- 顯示網絡鏈接:netstat [--tcp|-t] [--udp|-u] ...
- -t:TCP協議的相關鏈接
- -u:UDP協議的相關鏈接
- -w:raw socket的相關鏈接
- -l:處於監聽狀態的鏈接
- -a:全部狀態
- -n:以數字格式顯示IP和Port
- -e:擴展格式
- -p:顯示相關的進程及PID
- 經常使用組合:-tan, -uan, -tnl, -unl, -tunlp...
- 顯示接口的統計數據:
- 全部接口:netstat -i
- 指定接口:netstat -I<IFace>
- ifup/ifdown命令:啓動/關閉接口
- 注意:經過配置文件/etc/sysconfig/network-scripts/ifcfg-IFACE來識別接口並完成配置
- 配置主機名
- hostname命令:配置主機名
- 查看:hostname
- 配置:hostname HOSTNAME
- 當前系統有效,重啓後無效
- hostnamectl命令(CentOS 7)
- 顯示當前主機名信息:hostnamectl status
- 設定主機名:hostnamectl set-hostname,永久有效
- 配置文件:/etc/sysconfig/network
- HOSTNAME=<HOSTNAME>
- 注意:此方法的設置不會當即生效;但之後會一直有效
- 配置DNS服務器指向
- 配置文件:/etc/resolv.conf
- 測試(host/nslookup/dig):
- dig -t A FQDN(FQDN表示主機名),FQDN->IP
- dig -x IP,IP->FQDN
- iproute2家族
- ip命令:查看及管理路由、設備、策略路由、隧道
- ip Object
- ip link:網絡設備配置
- ip link set xxxx:修改設備屬性
- dev NAME(default):指明要管理的設備,dev關鍵字能夠省略
- up和down:啓用或禁用設備
- multicast on或multicast off:啓用或禁用多播功能
- name NAME:改變設備名字
- ip link show:顯示設備屬性
- ip netns:管理網絡名稱空間
- ip netns add NAME:建立netns
- ip netns del NAME:刪除netns
- ip netns exec NAME COMMAND:在netns中運行命令
- ip netns list:列出全部的netns
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
IP命令用來取代ifconfig命令家族socket
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)