博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux - 常用网络操作
阅读量:6847 次
发布时间:2019-06-26

本文共 4622 字,大约阅读时间需要 15 分钟。

01 - Linux CentOS网络配置

02 - Linux查看端口状态

检测本机8080端口状态:netstat –apn | grep 8080

检测192.168.0.1主机的8080端口状态:telnet 192.168.0.1 8080nmap -sS -P0 -n -p 22 192.168.0.1
检测192.168.0.1主机的1到1024端口状态:nc -z 192.168.0.1 1-1024

# nmap -sS -P0 -n -p 22 10.140.0.135Starting Nmap 6.40 ( http://nmap.org ) at 2016-11-09 10:42 CSTNmap scan report for 10.140.0.135Host is up (0.00040s latency).PORT STATE SERVICE22/tcp open sshMAC Address: 08:00:27:3F:19:79 (Cadmus Computer Systems)Nmap done: 1 IP address (1 host up) scanned in 0.07 seconds # nmap -sS -P0 -n -p 80 10.140.0.135Starting Nmap 6.40 ( http://nmap.org ) at 2016-11-09 10:50 CSTNmap scan report for 10.140.0.135Host is up (0.00046s latency).PORT STATE SERVICE80/tcp closed httpMAC Address: 08:00:27:3F:19:79 (Cadmus Computer Systems)Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds

03 - Linux命令行设置CentOS计算机名称、hosts及网卡地址

$ echo "anliven" > /etc/hostname$ echo -e "192.168.16.166 master\n192.168.16.167 slave01\n192.168.16.168 slave02" >> /etc/hosts$ sed -i '/IPADDR/s/192.168.16.200/192.168.16.166/' /etc/sysconfig/network-scripts/ifcfg-enp0s8$ reboot

04 - Linux CentOS7关闭SELinux

  • 永久方法:修改/etc/selinux/config文件中设置SELINUX=disabled ,然后重启。
# getenforceEnforcing# sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config# reboot
  • 临时方法:执行setenforce 0命令设置SELinux成为permissive模式
sudo systemctl status firewalld.servicesudo systemctl stop firewalld.service          sudo systemctl disable firewalld.service

05 - Ubuntu安装ssh并允许root登录

  1. Install openssh-server
apt-get updateapt-get install openssh-server
  1. Change ssh configuration
root@anliven:~# vim /etc/ssh/sshd_config root@anliven:~# root@anliven:~# cat /etc/ssh/sshd_config |grep RootLogin#PermitRootLogin without-passwordPermitRootLogin yes# the setting of "PermitRootLogin without-password".root@anliven:~# root@anliven:~# /etc/init.d/ssh restartssh stop/waitingssh start/running, process 3782root@anliven:~#
  1. Check ssh status
root@anliven:~# lsof -i:22COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAMEsshd    3630 root    3u  IPv4  19611      0t0  TCP *:ssh (LISTEN)sshd    3630 root    4u  IPv6  19613      0t0  TCP *:ssh (LISTEN)root@anliven:~# root@anliven:~# ps -ef |grep sshroot      3630     1  0 13:43 ?        00:00:00 /usr/sbin/sshd -D    root      3750  3732  0 13:46 pts/1    00:00:00 grep --color=auto sshroot@anliven:~#

06 - Linux常用网络软件包

  • inetuils-ping --- ping
  • net-tools --- ifconfig/route/netstat/......
  • iproute --- ip
  • traceroute
  • bind-utils --- nslookup/dig/host/......
  • bridge-utils --- brctl
  • nmap
  • tcpdump
  • wireshark
  • curl
  • wget
    ......

07 - Linux设置ssh免密码认证

示例:slave01和slave02两个主机ssh免密码相互登录

### 设置slave01 node[hadoop@slave01 ~]$ ssh-keygen[hadoop@slave01 ~]$ [hadoop@slave01 ~]$ cd .ssh[hadoop@slave01 .ssh]$ ssh-copy-id -i hadoop@slave01[hadoop@slave01 .ssh]$ ssh-copy-id -i hadoop@slave02[hadoop@slave01 .ssh]$ [hadoop@slave01 .ssh]$ ll -atotal 20drwx------  2 hadoop hadoop   76 Mar  7 23:34 .drwx------. 6 hadoop hadoop 4096 Mar  7 23:30 ..-rw-------  1 hadoop hadoop 1187 Mar  7 23:34 authorized_keys-rw-------  1 hadoop hadoop 1675 Mar  7 23:33 id_rsa-rw-r--r--  1 hadoop hadoop  396 Mar  7 23:33 id_rsa.pub-rw-r--r--  1 hadoop hadoop  551 Mar  7 23:34 known_hosts[hadoop@slave01 .ssh]$ ### 设置slave02 node[hadoop@slave02 ~]$ ssh-keygen[hadoop@slave02 ~]$ [hadoop@slave02 ~]$ cd .ssh[hadoop@slave02 .ssh]$ ssh-copy-id -i hadoop@slave01[hadoop@slave02 .ssh]$ ssh-copy-id -i hadoop@slave02[hadoop@slave02 .ssh]$ [hadoop@slave02 .ssh]$ ll -atotal 20drwx------  2 hadoop hadoop   76 Mar  7 23:35 .drwx------. 6 hadoop hadoop 4096 Mar  7 23:30 ..-rw-------  1 hadoop hadoop 1187 Mar  7 23:35 authorized_keys-rw-------  1 hadoop hadoop 1675 Mar  7 23:33 id_rsa-rw-r--r--  1 hadoop hadoop  396 Mar  7 23:33 id_rsa.pub-rw-r--r--  1 hadoop hadoop  551 Mar  7 23:35 known_hosts[hadoop@slave01 .ssh]$

08 - Linux设置路由并指定metric值

  • 默认路由:route add default gw 10.0.2.2 metric 1
  • 指定路由:route add 192.168.0.0 mask 255.255.0.0 192.168.16.1 metric 10

09 - Linux虚拟机出现多个默认路由,导致部分网络连接异常

# route -nKernel IP routing tableDestination     Gateway         Genmask         Flags Metric Ref    Use Iface0.0.0.0         192.168.16.1    0.0.0.0         UG    100    0        0 enp0s30.0.0.0         10.0.3.2        0.0.0.0         UG    101    0        0 enp0s8......

处理方法:更改网关192.168.16.1的路由设置。

  • CentOS7:应用程序---》系统工具---》设置---》网络---》以太网(enp0s3),点击右下角的设置按钮---》IPv4---》选择“仅对此网络上的资源使用此连接”---》应用。
  • Ubuntu1604:系统设置---》网络---》有线,选择对应网卡---》选项---》IPv4设置---》路由---》选择“仅将此连接用于相对应的网络上的资源”---》确定。
# route -n......192.168.16.0    0.0.0.0         255.255.255.0   U     100    0        0 enp0s3......

10 - xxx

转载于:https://www.cnblogs.com/anliven/p/7571948.html

你可能感兴趣的文章
SQLSERVER排查CPU占用高的情况
查看>>
PHP开发Android应用程序(转)
查看>>
Knockout.js随手记(8)
查看>>
mysql 安装过程中的错误:my-template.ini could not be processed and written to XXX\my.ini.Error code-1...
查看>>
计算A/3,不用除法
查看>>
ERStudio的使用
查看>>
git 本地与服务器的同步
查看>>
css鼠标移动到文字上怎样变化背景颜色
查看>>
HBase 实战(1)--HBase的数据导入方式
查看>>
浅谈WEB页面提速(前端向)
查看>>
05 语句处理
查看>>
LKD3
查看>>
搭建 SMTP mail
查看>>
WorldWind源码剖析系列:大气层散射球类AtmosphericScatteringSphere
查看>>
数组中的逆序对
查看>>
oracle数据库高级应用之《自动生成指定表的insert,update,delete语句》
查看>>
POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
查看>>
Python爬虫实战(三):爬网易新闻
查看>>
前端总结
查看>>
java代理
查看>>