天天看點

網絡

##################1.網絡基礎知識

(1)一台主機如果可以連接配接公網比如通路www.baidu.com,那麼這台主機必然會有

Ipaddress    

GATEWAY    

dns

(2)Ipaddress

 ipv4

2進制32位-----10進制

172.25.0.10/255.255.255.0

11111110.11111110.11111110.11111110/11111111.11111111.11111111.00000000

172.25.0.10ip位址

255.255.255.0子網路遮罩

子網路遮罩255位對應的ip位為網絡位

子網路遮罩0對應的ip位為主機位

##################2.ip的設定

ifconfig###檢視或者臨時設定主機ip的工具(同ip  addr  show)

ifconfig 網絡接口##檢視這個接口上的 ip

systemctl restart network###重新啟動網絡基本服務

systemctl restart NetworkManager###網絡智能管理服務

1圖形中網絡設定方式(永久設定)

nm-connection-editor##圖形中的網絡設定工具

nmtui##文本中的網絡設定工具

網絡
網絡

2ifconfig臨時設定

ifconfig 網絡接口 ip netmask 子網路遮罩####臨時設定ip

ifconfig eth0 172.25.254.100 netmask 255.255.255.0

(3)nmcli指令設定ip不會随重新開機服務或電腦而發生變化

nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes  ####添加動态網絡

nmcli connection add type ethernet con-name westos ifname eth0 ip4 ip/24 ##3添加靜态網絡

nmcli connection delete westos      westos表示連結名稱###删除此連結       

nmcli connection show

nmcli connection down westos

nmcli connection up westos

nmcli connection modify "westos" ipv4.addresses newip/24

nmcli connection modify "westos" ipv4.method <auto|manual>

nmcli device connect eth0

nmcli device disconnect eth0            ###斷開網的連接配接

nmcli device show

nmcli device status

(4)通過配置檔案重新開機服務來配置位址

dhcp##動态擷取

vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0##接口使用裝置

BOOTPROTO=dhcp##網卡工作模式

ONBOOT=yes##網絡服務開啟時自動激活

NAME=eth0##網絡接口名稱

wq

systemctl restart network

static|none##靜态網絡

DEVICE=eth0

BOOTPROTO=static|none

ONBOOT=yes

NAME=eth0

IPADDR=172.25.0.100  ##IP

NETNASK=255.255.255.0 | PREFIX=24 ##子網路遮罩

############3.getway

1.路由器

主要功能是用來作nat的

dnat   目的地位址轉換

snat   源位址轉換

2.網關

路由器上和自己處在同一個網段的那個ip

3.設定網關

systemctl stop NetwrokManager

vim /etc/sysconfig/network##全局網關

GATEWAY=網關ip

vim /etc/sysconfig/network-scripts/ifcfg-網卡配置檔案 ##網卡接口網關

systemctl restart netwrok

rout -n##查詢網關

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

0.0.0.0   (網關)172.25.0.254    0.0.0.0         UG    0      0        0 eth0

172.25.0.0      0.0.0.0         255.255.255.0   U     0      0        0 eth0

##################4.dns

1.dns

dns是一台伺服器

這台伺服器提供了回答客戶主機名和ip對應關系的功能

2.設定dns

vim /etc/resolv.conf

nameserver dns伺服器ip

vim /etc/sysconfig/network-scripts/ifcfg-網卡配置檔案

DNS1=dns伺服器ip

3.本地解析檔案

vim /etc/hosts

ip主機名稱

4.本地解析檔案和dns讀取的優先級調整

/etc/nsswitch.conf

 38 #hosts:     db files nisplus nis dns

 39 hosts:      files dns##files代表本地解析檔案dns代表dns伺服器那個在前面那個優先

5.dhcp配置檔案

yum install dhcp -y

cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example   /etc/dhcp/dhcpd

vim /etc/dhcp/dhcpd

網絡

删除27行

上一篇: 網絡
下一篇: 網絡

繼續閱讀