linux中网络配置二

一、设定DNS       ##地址解析

系统操作者对字符敏感

系统网络通信需要通过ip地址这个数字

当操作者输入网址www.baidu.com,这个网址不是一个可以通信的IP地址

于是必须要在系统中把www.baidu.com变成百度服务器的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-xxxx

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

interfaces: 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

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值