天天看點

Linux學習 Unit 11

Unit11.管理網絡

1.ip基礎知識

1.ipv4

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

172.25.0.10/255.255.255.0

172.25.0.10:ip位址

255.255.255.0:子網路遮罩

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

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

2.配置ip

<<圖形化>>

1.圖形界面

nm-connection-editor

2.文本化圖形

nmtui

<<指令>>

ifconfig 網卡 ip netmask                   ##臨時設定

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

nmcli connection delete 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

<<檔案>>

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

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

3.gateway 網關

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

route -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

5.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服務的配置

本文轉自  夏梨巴人  51CTO部落格,原文連結:http://blog.51cto.com/12774035/1915653

繼續閱讀