1. 程式人生 > >linux菜鳥基礎學習 (六) 網絡

linux菜鳥基礎學習 (六) 網絡

ice ping 9.1 del system fff 設定 ane sco

linux下的網絡配置

1.什麽是IP ADDRESS

  internet protocol ADDRESS ##網絡協議地址
    ipv4    internet protocol version 4
    1.2x32
    ip是由32個0和1組成
    11111110.11111110.11111110.11111110 = 254.254.254.254

2.子網掩碼

用來劃分網絡區域
子網掩碼非0的位對應的ip上的數字表示這個ip的網絡位
子網掩碼0位對應的數字是ip的主機位
網絡位表示網絡區域
主機位表示網絡區域裏的某臺主機

3.ip通信判定

網絡位一致,主機位不一致的兩個IP可以直接通信
172.25.254.1/24     24=255.255.255.0
172.25.254.2/24
172.25.0.1/16

4.網絡設定工具

ping        ##檢測網絡是否通暢
ifconfig    ##查看或設定網絡接口
ifconfig device ip/24   ##設定網絡
ifconfig device down    ##關閉
ifconfig device up  ##開啟

技術分享圖片

技術分享圖片

技術分享圖片

5.圖形方式設定ip

1.nm-connection-editor

2.nmtui

6.命令方式設定網絡

nmcli

nmcli device connect eth0   ##啟用eth0網卡
nmcli device disconnect eth0    ##關閉eth0網卡
nmcli device show eth0      ##查看網卡信息
nmcli device status eth0    ##查看網卡服務接口信息

nmcli connection show
nmcli connection down westos
nmcli connection up westos
nmcli connection delete westos
nmcli connection add type ethernet con-name westos ifname eth0 ip4 172.25.254.100/24
nmcli connection modify westos ipv4.method auto
nmcli connection modify westos ipv4.method manual
nmcli connection modify westos ipv4.addresses 172.25.254.150/24

技術分享圖片

技術分享圖片

技術分享圖片

技術分享圖片

技術分享圖片

技術分享圖片

技術分享圖片

技術分享圖片

7.管理網絡配置文件

網絡配置目錄
/etc/sysconfig/network-scripts
網絡配置文件的命名規則
ifcfg-xxx
DEVICE=xxx          ##設備名稱
BOOTPROTO=dhcp|static|none  ##設備的工作方式
ONBOOT=yes          ##網絡服務開啟時自動激活網卡
IPADDR=             ##IP地址
PREFIX=24           ##子網掩碼
NETMASK=255.255.255.0       ##子網掩碼

示例:
靜態網絡設定文件
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=172.25.254.100
NETMASK=255.255.255.0
BOOTPROTO=none
NAME=westos

systemctl restart network

技術分享圖片

技術分享圖片

技術分享圖片

技術分享圖片

一塊網卡上配置多個IP
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
IPADDR0=172.25.254.100
NETMASK0=255.255.255.0
BOOTPROTO=none
NAME=westos
IPADDR1=172.25.0.100
PREFIX1=24

systemctl restart network

ip addr show eth0

8.lo回環接口

9.網關

1.把真實主機變成路由器

firewall-cmd --list-all
firewall-cmd --permanent --add-masquerade
firewall-cmd --reload

2.設定虛擬機網關
vim /etc/sysconfig/network
GATEWAY=172.25.254.250

10.設定dns

doamin name system

vim /etc/hosts          ##本地解析文件
ip      域名
61.135.169.121  www.baidu.com

vim /etc/resolv.conf        ##dns指向文件
nameserver  114.114.114.114

vim /etc/sysconfig/network-scripts/ifcfg-eth0
DNS1=114.114.114.114

11.設定解析優先級

系統默認
/etc/hosts > /etc/resolv.conf

vim /etc/nsswitch.conf
39 hosts:   files   dns ##/etc/hosts優先

vim /etc/nsswitch.conf
39 hosts:       dns files     ##/etc/resolv.conf優先

12.dhcp服務配置

linux菜鳥基礎學習 (六) 網絡