当前位置:   article > 正文

Linux常用命令整理—网络_linux指令拼网络

linux指令拼网络

0.1网络配置

配置静态网络:https://blog.csdn.net/qq_46237746/article/details/124532376

02.查看ip

[root@hadoop100 ~]# hostname -i
192.168.10.100
  • 1
  • 2
[root@hadoop100 ~]# ifconfig
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::42:3aff:fe6a:334a  prefixlen 64  scopeid 0x20<link>
        ether 02:42:3a:6a:33:4a  txqueuelen 0  (Ethernet)
        RX packets 106775  bytes 32705809 (31.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 106785  bytes 34201827 (32.6 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.50  netmask 255.255.255.0  broadcast 192.168.10.255
        inet6 fe80::4858:ffc9:dee5:1904  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:27:4d:95  txqueuelen 1000  (Ethernet)
        RX packets 1163694  bytes 86105685 (82.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1830739  bytes 513445790 (489.6 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
//TODO
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

03.拼接别的网络

[root@hadoop100 ~]# ping www.baidu.com
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=128 time=11.5 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=128 time=11.4 ms
  • 1
  • 2
  • 3
  • 4

04.防火墙操作

查看防火墙状态

[root@hadoop100 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 二 2022-05-03 20:36:45 CST; 56min ago		# running说明防火墙正在打开
     Docs: man:firewalld(1)
 Main PID: 783 (firewalld)
   Memory: 30.1M
   CGroup: /system.slice/firewalld.service
           └─783 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

临时关闭防火墙

[root@hadoop100 ~]# systemctl stop firewalld
  • 1

开启防火墙

[root@hadoop100 ~]# systemctl start firewalld
  • 1

重启防火墙

[root@hadoop100 ~]# systemctl restart firewalld.service
  • 1

查看防火墙开机启动状态

[root@hadoop100 ~]# systemctl enable firewalld.service
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/basic.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.
  • 1
  • 2
  • 3

设置开机时关闭防火墙

[root@hadoop100 ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
  • 1
  • 2
  • 3

05.端口操作

查看当前监听的所有端口/端口占用情况

[root@hadoop100 ~]# netstat -ntulp		
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      3472/docker-proxy   
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      3430/docker-proxy   
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 0.0.0.0:9200            0.0.0.0:*               LISTEN      3679/docker-proxy  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

参数说明:

  • -t (tcp) 仅显示tcp相关选项
  • -u (udp)仅显示udp相关选项
  • -n 拒绝显示别名,能显示数字的全部转化为数字
  • -l 仅列出在Listen(监听)的服务状态
  • -p 显示建立相关链接的程序名

查看某个端口的使用情况

[root@hadoop100 ~]# netstat -ntulp |grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      3164/docker-proxy   
tcp6       0      0 :::3306                 :::*                    LISTEN      3170/docker-proxy 
  • 1
  • 2
  • 3

永久打开端口

[root@hadoop100 ~]# firewall-cmd --add-port=801/tcp --permanent
success
  • 1
  • 2

重新载入配置

[root@hadoop100 ~]# firewall-cmd --reload
success
  • 1
  • 2

查看端口是否开启

[root@hadoop100 ~]# firewall-cmd --query-port=801/tcp
yes
  • 1
  • 2

注意:打开端口并不意味着端口被监听或者被占用,若端口只打开未被监听,则查看端口监听情况依旧为空,具体如下:

[root@hadoop100 ~]# netstat -ntulp |grep 801
[root@hadoop100 ~]# 
  • 1
  • 2

永久关闭端口

[root@hadoop100 ~]# firewall-cmd --permanent --remove-port=801/tcp
success
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/912021
推荐阅读
相关标签
  

闽ICP备14008679号