linux中網路配置二

2021-10-06 04:20:42 字數 2486 閱讀 7257

一、設定dns       ##位址解析

系統操作者對字元敏感

系統網路通訊需要通過ip位址這個數字

這樣的過程叫做位址解析

dns伺服器:domain name server == 網域名稱解析服務 ##解析就是把網域名稱變成ip

vim /etc/resolv.conf ##dns的指向檔案 不需要重新啟動網路立即生效

nameserver 114.114.114.114 ##當需要某個網域名稱的ip位址時去問 114.114.114.114

nameserver 8.8.8.8 ##問谷歌的ip

vim /etc/sysconfig/network-scripts/ifcfg-***x

dns1=114.114.114.114 ##需要重啟網路,當網路重新啟動

此引數會修改/etc/resolv.conf

vim /etc/hosts ##本地解析檔案,此檔案中直接提供位址解析

二、設定解析的優先順序

系統預設:

/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 dns指向優

三、閘道器

1.環境設定

實驗環境:

在horizon_carry單網絡卡主機中:

ens160:172.25.254.10 #不可ping通

2.把carry雙網絡卡主機變成路由器

<1>開啟位址偽裝功能

在carry雙網絡卡主機中

先生成橋接網絡卡ens224

ens160:172.25.254.20

ens224:192.168.0.20 #可以ping 通

[root@carry ~]# systemctl start firewalld #打**牆

[root@carry ~]# firewall-cmd --add-masquerade #臨時位址偽裝功能

success

[root@carry ~]# firewall-cmd --list-all

public (active)

target: default

icmp-block-inversion: no

inte***ces: ens160 ens224

sources:

services: cockpit dhcpv6-client ssh

ports:

protocols:

masquerade: yes 《位址偽裝功能開啟,真實主機變成路由器

forward-ports:

source-ports:

icmp-blocks:

rich rules:

<2>過濾確認位址偽裝功能開啟

[root@carry ~]# sysctl -a | grep ip_forward #過濾一遍

net.ipv4.ip_forward = 1 #位址偽裝功能開啟

net.ipv4.ip_forward_use_pmtu = 0

<3> 核心路由開啟位址偽裝功能

[root@carry ~]# vim /etc/sysctl.conf

sysctl settings are defined through files in

/usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.

vendors settings live in /usr/lib/sysctl.d/.

to override a whole file, create a new file with the same in

/etc/sysctl.d/ and put new settings there. to override

only specific settings, add a file with a lexically later

name in /etc/sysctl.d/ and put new settings there.

for more information, see sysctl.conf(5) and sysctl.d(5).

net.ipv4.ip_forward=1

[root@carry ~]# sysctl -p

net.ipv4.ip_forward = 1

linux中網路的管理

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位為主機位 圖形化 1.圖形介面 2.文字化圖形 nmtui 命令 ifconf...

Linux 中網路相關的那些配置檔案

etc networks 機器所連線的網路中那些可以訪問的網路名和網路位址 etc protocols 列舉了當前可用的協議名稱 etc resolv.conf dns伺服器資訊 search domainname.com nameserver 192.168.1.2 nameserver 8.8....

linux系統中網絡卡配置詳解

檔案 etc sysconfig network scripts ifcfg eth0 以下各值常見於所有的基本配置檔案中 device name,這裡name是物理裝置的名字 動態分配的ppp裝置應當除外,它的名字是 邏輯名 ipaddr addr,這裡addr是ip位址。netmask mask...