Linux - 常用网络操作
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 8080 或nmap -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登录
- Install openssh-server
apt-get update
apt-get install openssh-server
- 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:~#
- 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 - 常用网络操作的更多相关文章
- Linux常用网络测试命令
Linux常用网络测试命令 1. ifconfig 可以使用ifconfig命令来配置并查看网络接口的配置情况. 例如: (1) 配置eth0的IP地址, 同时激活该设备. #ifcon ...
- linux常用网络命令ping和arping
linux常用网络命令ping和arping ping 向目标主机发送icmp请求包 常用来测试当前主机与目标主机网络连接状况 常见选项 -c 设置发包的个数 -s ...
- Linux常用网络工具:路由扫描之mtr
除了上一篇<Linux常用网络工具:路由扫描之traceroute>介绍的traceroute之外,一般Linux还内置了另一个常用的路由扫描工具mtr. mtr在某些方面比tracero ...
- Linux常用网络工具:路由扫描之traceroute
之前两篇<Linux常用网络工具:fping主机扫描>和<Linux常用网络工具:hping高级主机扫描>都是关于主机扫描的,本篇介绍Linux下常用的路由扫描工具tracer ...
- Linux常用网络工具:hping高级主机扫描
之前介绍了主机扫描工具fping,可以参考我写的<Linux常用网络工具:fping主机扫描>. hping是一款更高级的主机扫描工具,它支持TCP/IP数据包构造.分析,在某些防火墙配置 ...
- Unix/Linux常用文件操作
Unix/Linux常用文件操作 秘籍:man命令是Unix/Linux中最常用的命令,因为命令行命令过多,我相信每个人都会经常忘记某些命令的用法,man命令就可以显示一个命令的所有选项,参数和说明, ...
- linux下常用网络操作汇总
首先说明下RHEL6下设置IP地址的确和RHEL5下有几点是不同的. 我装完RHEL6中默认选择的是DHCP自动获取方式: [root@localhost ~]# vi /etc/sysconfig/ ...
- linux下常用网络操作汇总 专题
centos 更改主机名,需要更改的几个地方: (1) /etc/sysconfig/network //更改主机名(2)/etc/hostname //更改主机名(3) /etc/hosts ...
- 八、Linux上常用网络操作
1. 主机名配置 hostname 查看主机名 hostname xxx 修改主机名 重启后无效 如果想要永久生效,可以修改/etc/sysconfig/network文件 2. IP地址配置 set ...
随机推荐
- AR涂涂乐
<1> 涂涂乐着色 https://blog.csdn.net/begonia__z/article/details/51282932 http://www.manew.com/blog- ...
- wiredtiger--初学数据恢复
启动mongodb是failed,日志如下 1.解压wirdtiger包 tar -vxf wiredtiger-3.1.0.tar.bz2 -C /home/wiredtiger/ 2.安装snap ...
- ES6中的let命令
ES6新增了let命令,用于声明变量.其用法类似var,区别是使用let命令声明的变量只在当前代码块有效. for循环的计数器就很适合使用let命令. var arr= [1,2,3,4,5]; fo ...
- 大数据入门到精通13--为后续和MySQL数据库准备
We will be using the sakila database extensively inside the rest of the course and it would be great ...
- mysql修改密码方法
1. 修改密码有三种方法:1.1 ---->用mysqladmin修改密码格式:mysqladmin -u用户名 -p旧密码 password 新密码 例子:# mysqladmin -uroo ...
- 微服务SpringCloud无法进行服务消费
最近用SpringCloud做微服务,一直无法成功进行服务消费. 我使用的服务消费者是Feign,声明式调用服务提供者. 排查过程 1.检查服务提供者: (1)对提供的方法进行测试,确保提供的服务没有 ...
- vue的条件渲染和列表渲染介绍
一.条件渲染 1.v-if语句 <div v-if="seen">hahahah</div> <!-- v-if插入或者删除元素的指令 --> ...
- 【转载】Windows上那些值得推荐的良心软件-整理 easybcd 引导工具 easyuefi 引导工具
您查询的关键词是:清理dism知乎 以下是该网页在北京时间 2019年03月17日 21:56:16 的快照: 如果打开速度慢,可以尝试快速版:如果想更新或删除快照,可以投诉快照. 百度和网页 htt ...
- [leetcode]54. Spiral Matrix螺旋矩阵
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...
- PHP+ajax实现二级联动
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...