• 408-Linux基础(网络管理:ifconfig、ping、netstat)


    1、ifconfig命令

    ifconfig 英文全拼network interfaces configuring,显示或配置网络设备。

    ifconfig 
    
    • 1

    在这里插入图片描述
    127.0.0.1这个ip可以访问你自己电脑,这个叫做本地回环

    虚拟机上添加一个网卡

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    临时性的将ens38这个网卡关掉:(重启之后又是可以使用的!)

    sudo ifconfig ens38 down
    
    • 1

    在这里插入图片描述

    开启网卡:

    sudo ifconfig ens38 up
    
    • 1

    在这里插入图片描述

    修改ens33网卡的ip地址:(这也是临时性的修改,重启之后也会失效)

    在这里插入图片描述

    sudo ifconfig ens33 192.168.30.233
    
    • 1

    在这里插入图片描述
    这里设置的是动态ip。

    2、设置静态IP

    sudo vi /etc/network/interfaces
    
    • 1

    在这里插入图片描述
    显示只配置了一个本地回环的!

    在这里插入图片描述

    修改好之后需要重启之后才能生效:

    reboot
    
    • 1

    修改dns解析

    因为以前是dhcp解析,所以会自动分配dns服务器地址,而一旦设置为静态ip后,就没有自动获取到的dns服务器了,要自己设置一个:

    sudo vi /etc/resolv.conf
    
    • 1

    写上一个公网的DNS:

    nameserver 114.114.114.114
    
    • 1

    在这里插入图片描述

    重启网卡:

    sudo /etc/init.d/networking restart
    
    • 1

    如果还不生效重启系统!

    3、ping命令

    ping脉冲,向远端IP地址发送ICMP(Internet Control Message Protocol)协议的数据包,检测网络状态;

    where@ubuntu:~$ ping 192.168.1.1
    PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
    64 bytes from 192.168.1.1: icmp_seq=1 ttl=128 time=453 ms
    64 bytes from 192.168.1.1: icmp_seq=2 ttl=128 time=5.86 ms
    64 bytes from 192.168.1.1: icmp_seq=3 ttl=128 time=35.7 ms
    64 bytes from 192.168.1.1: icmp_seq=4 ttl=128 time=5.33 ms
    64 bytes from 192.168.1.1: icmp_seq=5 ttl=128 time=4.37 ms
    64 bytes from 192.168.1.1: icmp_seq=6 ttl=128 time=3.54 ms
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    也可以向域名发送数据包:

    where@ubuntu:~$ ping www.baidu.com
    PING www.a.shifen.com (14.215.177.37) 56(84) bytes of data.
    64 bytes from 14.215.177.37: icmp_seq=1 ttl=128 time=18.2 ms
    64 bytes from 14.215.177.37: icmp_seq=2 ttl=128 time=14.4 ms
    64 bytes from 14.215.177.37: icmp_seq=3 ttl=128 time=12.3 ms
    64 bytes from 14.215.177.37: icmp_seq=4 ttl=128 time=23.0 ms
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    4、netstat命令

    查看当前网络接口信息。

    ‐a #显示所有socket,包括正在监听的。
    ‐c #每隔1秒就重新显示一遍,直到用户中断它。
    ‐n #以网络IP地址代替名称,显示出网络连接情形,显示端口。
    ‐t #显示TCP协议的连接情况。
    ‐u #显示UDP协议的连接情况。
    ‐p #显示建立相关链接的程序名。
    ‐l #查看正在处于监听状态的程序。
    #LISTEN和LISTENING的状态只有用‐a或者‐l才能看到

    看tcp和udp协议:
    在这里插入图片描述

    sudo netstat -anp | grep apache
    
    • 1

    在这里插入图片描述
    80表示80端口,前面的0表示任意的ip都可以访问。

    sudo netstat -lnp	#查看正在处于监听状态的程序
    
    • 1

    在这里插入图片描述

  • 相关阅读:
    php魔术方法和反序列化漏洞
    以一道面试题来探讨测试用例设计的六大思路
    全屋智能--智慧家庭新风向
    IP代理安全吗?如何防止IP被限制访问?
    LNMP架构之搭建Discuz论坛
    Android 运行报错:Circular dependencies cannot exist in RelativeLayout
    架构师书籍推荐
    初探七层网络协议
    Linux学习——线程的创建和回收
    20231116模拟赛题解
  • 原文地址:https://blog.csdn.net/Edward_LF/article/details/125413509