wy168 发表于 2023-5-4 19:34:04

Macbook同时访问内外网


    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">大公司里一般都会搭建内网环境,为了网络安全,内外网隔离。在内网环境中如果想访问外网,需要走公司的代理。一般情况下公司代理都会屏蔽一些地址,因此我们不得不频繁的在内外网之间进行切换...这降低了工作效率不说,也降低了我们的工作热情。有没有办法破解呢?</p>
    <h1 style="text-align: left; margin-bottom: 10px;">目标</h1>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">Macbook上连接外网wifi的同时,也插上内网网线,可以同时访问公司内网和外网。</span></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">原理:通过设置网卡优先级、配置路由表,分发网络。</span></p>
    <h1 style="text-align: left; margin-bottom: 10px;">检查并修改网络优先级</h1>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">默认情况下,mac的网络优先级是先走网线,然后是wifi,再是其他。如果是这样,我们同时插上网线和连接wifi,只能访问内网而无法访问外网,因为此时所有的请求都发往内网网关了。因此需要调整网络优先级。</span></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">在macbook的【设置-&gt;网络-&gt;设定服务顺序】中,把wifi排在最上面。</span></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">先在左侧网络属性这里,找到“设定服务顺序”,如下图:</span></p>
    <div style="text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/019b3ea6455f4fae9047f965ab68490b~noop.image?_iz=58558&amp;from=article.pc_detail&amp;x-expires=1679809377&amp;x-signature=LTwM6KADbNAsribTADlgBQbGvOE%3D" style="width: 100%; margin-bottom: 20px;">
      <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">设置网卡优先级</p>
    </div>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">然后选中wifi,</span><span style="color: green;">拖动</span>到最上面的位置:</p>
    <div style="text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/df83e219369544eaa73791c25c1a87ce~noop.image?_iz=58558&amp;from=article.pc_detail&amp;x-expires=1679809377&amp;x-signature=PxCwg7PohvV%2BIbGwu6Q7lipl1hc%3D" style="width: 100%; margin-bottom: 20px;">
      <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">调高无线网卡优先级</p>
    </div>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">这时,网络就会优先走wifi。但是我们只能访问外网,而无法访问内网了。因为所有的请求都走了wifi。</span></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">如何解决?</span></p>
    <h1 style="text-align: left; margin-bottom: 10px;">添加内网路由</h1>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">由于内网地址是固定的,所以可以通过添加内网路由,来指定我们的请求所走的网关。</span></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">在命令行中添加路由指令:</span></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">networksetup -setadditionalroutes "AX88772A" 10.100.22.0 255.255.255.0 10.4.120.1 10.100.120.0 255.255.255.0 10.4.120.1 10.170.33.0 255.255.255.0 10.4.120.1 10.30.32.0 255.255.255.0 10.4.120.1 10.4.0.0 255.255.0.0 10.4.120.1 33.33.43.0 255.255.255.0 10.4.120.1 192.168.0.0 255.255.0.0 10.4.120.1</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">其中,“AX88772A” 是我连接网线的网络名称,这个可以在【设置-&gt;网络】中查看,也可以通过命令行查看,如下:</span></p><span style="color: green;">查看网络名称:</span>
    <span style="color: green;">networksetup</span> <span style="color: green;">-listallnetworkservices</span>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">结果可能如下:</span></p>
    <div style="text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/d723bddd92a54c94a57e63d74f636ac5~noop.image?_iz=58558&amp;from=article.pc_detail&amp;x-expires=1679809377&amp;x-signature=oAl9nYPfYWE%2BjtQGaL9JD2ccBsQ%3D" style="width: 100%; margin-bottom: 20px;">
      <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">网络设备</p>
    </div>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">10.100.22.0 255.255.255.0 10.4.120.1,分别为目标地址段、子网掩码、网关地址。每3个地址为一组,如果有多个目标地址需求,就可以按照上面的形式来填写。</span></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">目标地址段和子网掩码,配置的是我们要访问的内网地址。如内网服务器、内网OA等,按需配置地址段。</span></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">网关地址,就是内网网关。</span></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">内网网关地址可以咨询公司的网络管理员。</span></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">或者在连接内网网线的情况下执行【netstat -rn】来查看。</span></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">设置完成后可以执行“networksetup -getadditionalroutes 网络名”查看效果:</span></p>
    <div style="text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/2043729d6eaa4cefb335c77fd69dead7~noop.image?_iz=58558&amp;from=article.pc_detail&amp;x-expires=1679809377&amp;x-signature=5h7wm3nxF2ahxmGIGkrpeTLJDPg%3D" style="width: 100%; margin-bottom: 20px;">
      <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">查看路由设置</p>
    </div>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">这时,我们就可以既访问内网,又可以访问外网了,不需要再拔网线了!</span></p>
    <h1 style="text-align: left; margin-bottom: 10px;">删除路由</h1>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">如果出现意想不到的结果,可以执行如下指令删除路由配置:</span></p><span style="color: green;">networksetup</span> -setadditionalroutes <span style="color: green;">"AX88772A"</span>
    <h1 style="text-align: left; margin-bottom: 10px;">通过数据线使用iPhone网络</h1>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">iPhone通过数据线连接macbook时一般情况下会给mac提供网络,这时既可以使用网络,又可以给手机充电,没必要通过wifi连接手机热点。</span></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">但如果想在这种情况下同时访问内外网,记得要调整网络优先级哟!</span></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">把USB 10/100/1000 LAN调到网线网络的上面即可。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">​</span></p>


页: [1]
查看完整版本: Macbook同时访问内外网