• 【收藏】window、mac、linux的ip、路由与dns配置教程


    1、window配置

    window查看ip:ipconfig

    window查看路由:route print

    window添加路由:route add 10.5.0.0 mask 255.255.0.0 -p 10.87.22.254

    window删除路由:route delete 10.5.0.0 mask 255.255.0.0 -p 10.87.22.254

    window路由追踪:tracert 10.5.5.1

    window查看dns服务器:nslookup

    window刷新dns:

    输入:ipconfig /flushdns  释放DNS缓存;

    输入:netsh winsock reset  重置Winsock目录;

    2、mac配置

    mac查看ip信息:ipconfig

    mac查看路由:netstat -nr

    mac添加路由:route  add -net 10.5.0.0/16 10.87.22.254

    mac删除路由:route  delete  -net 10.5.0.0/16 10.87.22.254

    mac查看dns:cat /etc/resolv.conf

    mac刷新dns缓存:

    sudo killall -HUP mDNSResponder

    echo macOS DNS Cache Reset

    1. (mac添加永久路由要用下面的方式:
    2. ```
    3. $ networksetup -listallnetworkservices        #查看网口设备
    4. $ networksetup -setadditionalroutes "Ethernet" 10.188.12.0 255.255.255.0 192.168.8.254
    5. 10.73.82.0 255.255.225.0 192.168.8.254        #添加路由,会覆盖,所以需要添加多条路由的话,一次性添加,这里添加了2条路由
    6. $ networksetup -setadditionalroutes Ethernet   #清空路由
    7. $ networksetup -getadditionalroutes Ethernet    #查看路由
    8. ```

    3、linux

    linux查看ip:ifconfig  或者ip a

    linux路由追踪:traceroute 10.5.5.1

    linux添加路由 route add -net 10.5.0.0/16 gw 10.87.22.254

    linux查看dns:cat /etc/resolv.conf

    linux刷新dns:linux本身没有dns缓存服务,如果有开启相关dns服务,grep dns服务后重启即可;

    nmcli命令配置IP

    #                       网卡名

    nmcli connection delete ens18

    #                                         网卡名         网卡名               IP/掩码                  网关

    nmcli connection add type ethernet ifname ens18 con-name ens18 ipv4.addresses 10.1.1.2/24 ipv4.gateway 10.1.2.254 ipv4.method manual

    #                   网卡名

    nmcli connection up ens18

    假设DNS是200.200.10.199
    echo "nameserver 200.200.10.199" >> /etc/resolv.conf

    ping www.baidu.com或www.google.com验证

    linux添加永久路由:

    在/etc/sysconfig/static-routes文件里面写入:

    如果该文件不存在,则手动创建,添加内容格式为:

    参照/etc/init.d/network文件里面的shell语句:

    1. ```
    2.     # Add non interface-specific static-routes.
    3.                 if [ -f /etc/sysconfig/static-routes ]; then
    4.                    grep "^any" /etc/sysconfig/static-routes | while read ignore args ; do
    5.                    /sbin/route add -$args
    6.                 done
    7.                 fi
    8. ```

    则,如果要添加一条静态路由,命令为:

    route add -net 192.56.76.0 netmask 255.255.255.0 dev eth1

    那么,在/etc/sysconfig/static-routes文件中添加格式为:

    any net 192.56.76.0/255.255.255.0 gw 192.56.76.254 dev eth0

  • 相关阅读:
    05 SpringBoot注册Web组件
    Ubuntu20.04 Server 安装NS3 速通版
    Android Media Framework - 开篇
    动态SQL
    低开开发笔记(八): 低代码编辑器实现撤销回退(命令模式,防抖处理)
    【MySQL】用户管理
    动态路由协议的分类、动静态路由优缺点、RIP简介、组播单播广播详解(附图)
    Go 单元测试之HTTP请求与API测试
    【PyQt小知识 - 4】:QGroupBox分组框控件 - 边框和标题设置
    【Python零基础入门篇 · 38】:正则的高级用法
  • 原文地址:https://blog.csdn.net/Mr_wilson_liu/article/details/126938784