Centos7 网络无法访问外网解决

嘿,兄弟,我这儿有点经验能跟你分享。
之前我遇到个事儿,跟你的情况有点像。
我有个Centos7 的虚拟机,弄了半天上不了外网,排查解决的过程还真是费了不少脑筋。

首先,你得看看虚拟机里的网卡设置。
在VirtualBox里,你点开虚拟机设置,找到“网络”这一栏,看看有没有选择“桥接模式”。
我之前那个没选,就改成了桥接模式。
然后,你还得进入Centos的/etc/resolv.conf文件,添加一个解析器。
我加了谷歌的解析器,写法是这样的:
nameserver 1 9 2 .1 6 8 .6 0.2 04 nameserver 1 9 2 .1 6 8 .6 0.2 02 nameserver 1 1 4 .1 1 4 .1 1 4 .1 1 4
说实话,我当时也没想明白为什么得加这个,但加了之后外网就通了。

如果这招不行,那咱们就得检查路由了。
看看有没有默认路由,没有的话得手动添加。
这事儿有三种方式可以搞定:
1 . 用route命令,比如这样:route add default gw 1 9 2 .1 6 8 .1 .1 ,这里的1 9 2 .1 6 8 .1 .1 是你的网关地址。

2 . 用ip命令,比如这样:ip route add default via 1 9 2 .1 6 8 .1 .1 dev eth0,这里的1 9 2 .1 6 8 .1 .1 和eth0分别是你的网关地址和网卡名称。

3 . 用sysctl命令,比如这样:sysctl -w net.ipv4 .ip_forward=1 ,然后添加默认路由:route add default gw 1 9 2 .1 6 8 .1 .1
这三种方法我试过,都挺管用。
希望这能帮到你,兄弟!

CentOS7使用hostapd实现无AP模式的详解

上周我朋友弄了个Linux路由器。
用hostapd。
挺简单的。

2 02 3 年3 月1 5 日。
我在家弄的。
两块网卡。
wlp2 s0无线。
eth0有线。

配置文件。
最小化。
/etc/hostapd/hostapd.conf interface=wlp2 s0 driver=nl8 02 1 1 ssid=test hw_mode=g channel=1 auth_algs=3 ignore_broadcast_ssid=0 wpa=3 wpa_passphrase=1 2 3 4 5 6 7 8
有线接口。
自动获取IP。
没问题。

无线接口。
用ip addr add。
ip addr add 1 7 2 .1 6 .0.1 /2 4 dev wlp2 s0
坑。
NetworkManager不让改。
用老方法。
新建文件 /etc/sysconfig/network-scripts/ifcfg-static-wlp2 s0 ONBOOT=yes IPADDR=1 7 2 .1 6 .0.1 PREFIX=2 4
停止NetworkManager。
systemctl stop NetworkManager.service 禁止开机启动。
systemctldisable NetworkManager.service
启用转发。
sysctl -w net.ipv4 .ip_forward=1 保存。
/etc/sysctl.d/ip_forward.conf
接口伪装。
firewalld。
systemctl start firewalld.service firewall-cmd --zone=trusted --add-interface=wlp2 s0 --permanent firewall-cmd --zone=public --add-masquerade --permanent systemctl restart firewalld.service
或者iptables。
systemctl stop firewalld.service systemctldisable firewalld.service yum install iptables-services systemctlenable iptables.service systemctl start iptables.service iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
dnsmasq。
yum install dnsmasq systemctlenablednsmasq.service vi /etc/dnsmasq.conf interface=wlp2 s0 dhcp-range=1 7 2 .1 6 .0.1 00,1 7 2 .1 6 .0.2 00,2 5 5 .2 5 5 .2 5 5 .0,1 h
重启hostapd。
systemctl restarthostapd.service
搞定。
你看着办。

CentOS7 配置静态IP为何总会出现一个动态IP?

关闭虚拟机网络。
卸载新增网卡。
重新添加网卡。
选择自定义桥接模式。
进入CentOS 7 系统: 1 . ipa看到两块网卡。
2 . cd /etc/sysconfig/network-scripts。
3 . cp 网卡1 网卡2 4 . vi 网卡2 修改NAME=设备名称。
删除UUID=内容。
5 . 重启网络。
重启网络无效。
重启CentOS 7 系统。
CentOS 7 重启后解决。
可能步骤不全。
欢迎更优方案。