01 - Linux CentOS网络配置
02 - Linux查看端口状态
检测本机8080端口状态:netstat –apn | grep 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.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登录
- Install openssh-server
apt-get updateapt-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-passwordPermitRootLogin yes# the setting of "PermitRootLogin without-password".root@anliven:~# root@anliven:~# /etc/init.d/ssh restartssh stop/waitingssh start/running, process 3782root@anliven:~#
- 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......