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

# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.16.1 0.0.0.0 UG 100 0 0 enp0s3
0.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
......

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.135
Starting Nmap 6.40 ( http://nmap.org ) at 2016-11-09 10:42 CST
Nmap scan report for 10.140.0.135
Host is up (0.00040s latency).
PORT STATE SERVICE
22/tcp open ssh
MAC 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.135
Starting Nmap 6.40 ( http://nmap.org ) at 2016-11-09 10:50 CST
Nmap scan report for 10.140.0.135
Host is up (0.00046s latency).
PORT STATE SERVICE
80/tcp closed http
MAC 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 ,然后重启。
# getenforce
Enforcing
# sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
# reboot
  • 临时方法:执行setenforce 0命令设置SELinux成为permissive模式
sudo systemctl status firewalld.service
sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service

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

  1. Install openssh-server
apt-get update
apt-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-password
PermitRootLogin yes
# the setting of "PermitRootLogin without-password".
root@anliven:~#
root@anliven:~# /etc/init.d/ssh restart
ssh stop/waiting
ssh start/running, process 3782
root@anliven:~#
  1. Check ssh status
root@anliven:~# lsof -i:22
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 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 ssh
root 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 ssh
root@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 -a
total 20
drwx------ 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 -a
total 20
drwx------ 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 -xxx

Linux - 常用网络操作的更多相关文章

  1. Linux常用网络测试命令

    Linux常用网络测试命令 1. ifconfig     可以使用ifconfig命令来配置并查看网络接口的配置情况.    例如: (1) 配置eth0的IP地址, 同时激活该设备. #ifcon ...

  2. linux常用网络命令ping和arping

    linux常用网络命令ping和arping ping 向目标主机发送icmp请求包 常用来测试当前主机与目标主机网络连接状况 常见选项 -c              设置发包的个数 -s      ...

  3. Linux常用网络工具:路由扫描之mtr

    除了上一篇<Linux常用网络工具:路由扫描之traceroute>介绍的traceroute之外,一般Linux还内置了另一个常用的路由扫描工具mtr. mtr在某些方面比tracero ...

  4. Linux常用网络工具:路由扫描之traceroute

    之前两篇<Linux常用网络工具:fping主机扫描>和<Linux常用网络工具:hping高级主机扫描>都是关于主机扫描的,本篇介绍Linux下常用的路由扫描工具tracer ...

  5. Linux常用网络工具:hping高级主机扫描

    之前介绍了主机扫描工具fping,可以参考我写的<Linux常用网络工具:fping主机扫描>. hping是一款更高级的主机扫描工具,它支持TCP/IP数据包构造.分析,在某些防火墙配置 ...

  6. Unix/Linux常用文件操作

    Unix/Linux常用文件操作 秘籍:man命令是Unix/Linux中最常用的命令,因为命令行命令过多,我相信每个人都会经常忘记某些命令的用法,man命令就可以显示一个命令的所有选项,参数和说明, ...

  7. linux下常用网络操作汇总

    首先说明下RHEL6下设置IP地址的确和RHEL5下有几点是不同的. 我装完RHEL6中默认选择的是DHCP自动获取方式: [root@localhost ~]# vi /etc/sysconfig/ ...

  8. linux下常用网络操作汇总 专题

    centos 更改主机名,需要更改的几个地方: (1) /etc/sysconfig/network  //更改主机名(2)/etc/hostname  //更改主机名(3) /etc/hosts   ...

  9. 八、Linux上常用网络操作

    1. 主机名配置 hostname 查看主机名 hostname xxx 修改主机名 重启后无效 如果想要永久生效,可以修改/etc/sysconfig/network文件 2. IP地址配置 set ...

随机推荐

  1. sh 了解

    shell 脚本中 `dirname $0` 在命令行状态下单纯的执行时没有意义的,因为他返回当前路径的“.”. 在脚本中他返回这个脚本文件放置的目录,并可以根据这个目录来定位所要运行的程序的相对位置 ...

  2. 【mac上安装&配置&使用git】

    转自:https://www.jianshu.com/p/7edb6b838a2e 目录 安装git 创建ssh key.配置git 提交本地项目到GitHub 一.安装Git MAC 上安装Git主 ...

  3. 247. Strobogrammatic Number II输出所有对称数字

    [抄题]: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at u ...

  4. python中sys.path--学习

    本着下定义开头吧:python中import某个A模块时,首先会从python的内置模块中查找是否含义该模块的定义若未查询到会从sys.path对应的模块路径查询是否含有对应模块的定义,如果搜索完成依 ...

  5. stark组件开发之批量操作

    class UserInfoHandler(StartHandler): ....... # 批量操作功能的列表,添加则显示, 使用此功能.需要将StartHandler.display_checkb ...

  6. mybatis的Sql语句打印

    我们在使用mybatis的时候,有时候,希望可以在eclipse的控制台下打印出来sql语句,但是有时候却不希望相关的语句打印.这个时候,需要我们进行一些配置.  在mybatis中,他通过调用一些接 ...

  7. C++字符串结束标识

    用一个字符数组可以存放一个字符串中的字符.如: char str[12]={'I',' ','a','m',' ','h','a','p','p','y'}; 用一维字符数组str来存放一个字符串″I ...

  8. VC 中引用js文件

    #include "comutil.h" using namespace MSScriptControl; #include <MsHTML.h> #include & ...

  9. [SoapUI] 从测试套件,测试用例,测试步骤,测试数据各个级别控制是否执行

    自动保存 # -*- coding: utf-8 -*- import java.awt.Color import org.apache.poi.ss.usermodel.Cell import or ...

  10. AX_Currency

    Currency::curAmount(9.23,"HKD");  Currency::curAmount2CurAmount(9.23,"RMB"," ...