CentOS VM下安裝(ssh、ftp)
OS :CentOS-7-x86_64-Minimal-1511.iso
VM : VMware 12 pro
第一次安裝作業系統類型選擇了 CentOS , 結果沒有網卡。無耐只好重裝。
第二次安裝作業系統類型選擇了CentOS7 64位 , 這次就有了網卡。
到這,作業系統安裝完成了,且已經能上網了
更新一下系統:sudo yum update && sudo yum upgrade
安裝ssh 、ftp : sudo yum install openssh vsftp
設定檔:ssh: /etc/ssh/ssh_config ftp: /etc/vsftpd/vsftpd.conf
開通服務:sudo service vsftpd/ssh [start|restart|stop]
查看連接埠是否開通:ss -ant
ftp上傳的配置:
getsebool -a | grep ftpd
setsebool ftpd_full_access on
service vsftpd restart
備忘:二代ip-tools的一些用法
一、ip ss指令替代 ifconfig route arp netstat
1、ip 指令入門
ip [ OPTIONS ] OBJECT { COMMAND | help }
OBJECT 和 COMMAND可以簡寫到一個字母
ip help 可以查到OBJECT列表和OPTIONS,簡寫 ip h
ip <OBJECT> help 查看針對該OBJECT的協助,比如 ip addr help,簡寫 ip a h
ip addr 查看網路介面地址,簡寫 ip a
查看網路介面地址,替代ifconfig:
[root@centos7 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:15:35:d2 brd ff:ff:ff:ff:ff:ff
inet 192.168.150.110/24 brd 192.168.150.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe15:35d2/64 scope link
valid_lft forever preferred_lft forever
[root@centos7 ~]#
網路介面統計資訊
[root@centos7 ~]# ip -s link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 0 0 0 0
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 08:00:27:15:35:d2 brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
8135366 131454 0 0 0 456
TX: bytes packets errors dropped carrier collsns
646297 2441 0 0 0 0
2、ip route顯示和設定路由
顯示路由表
[root@centos7 ~]# ip route
default via 192.168.150.254 dev enp0s3 proto static metric 1024
192.168.150.0/24 dev enp0s3 proto kernel scope link src 192.168.150.110
太難看了,格式化一下(顯示的是預設閘道和區域網路路由,兩行的內容沒有共通性):
[root@centos7 tmp]# ip route|column -t
default via 192.168.150.254 dev enp0s3 proto static metric 1024
192.168.150.0/24 dev enp0s3 proto kernel scope link src 192.168.150.110
添加靜態路由
[root@centos7 ~]# ip route add 10.15.150.0/24 via 192.168.150.253 dev enp0s3
[root@centos7 ~]#
[root@centos7 ~]# ip route|column -t
default via 192.168.150.254 dev enp0s3 proto static metric 1024
10.15.150.0/24 via 192.168.150.253 dev enp0s3 proto static metric 1
192.168.150.0/24 dev enp0s3 proto kernel scope link src 192.168.150.110
[root@centos7 ~]#
[root@centos7 ~]# ping 10.15.150.1
PING 10.15.150.1 (10.15.150.1) 56(84) bytes of data.
64 bytes from 10.15.150.1: icmp_seq=1 ttl=63 time=1.77 ms
64 bytes from 10.15.150.1: icmp_seq=1 ttl=63 time=1.08 ms
64 bytes from 10.15.150.1: icmp_seq=1 ttl=63 time=1.57 ms
^C
刪除靜態路由只需要把 add 替換成 del,或者更簡單的唯寫目標網路
[root@centos7 ~]# ip route del 10.15.150.0/24
[root@centos7 ~]#
但是,ip route 指令對路由的修改不能儲存,重啟就沒了。
設定永久的靜態路由的方法RHEL官網文檔講了幾種,實驗成功的只有一種:
[root@centos7 ~]#echo "10.15.150.0/24 via 192.168.150.253 dev enp0s3" > /etc/sysconfig/network-scripts/route-enp0s3
重啟電腦,或者禁用再啟用裝置enp0s3才會生效,
注意:/etc/sysconfig/static-routes,/etc/sysconfig/network 設定檔都不好用。
3、用 ip neighbor 代替 arp -n
[root@centos7 ~]# ip nei
192.168.150.254 dev enp0s3 lladdr b8:a3:86:37:bd:f8 STALE
192.168.150.100 dev enp0s3 lladdr 90:b1:1c:94:a1:20 DELAY
192.168.150.253 dev enp0s3 lladdr 00:09:0f:85:86:b9 STALE
4、用ss 代替 netstat
對應netstat -ant
[root@centos7 ~]# ss -ant
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:22 *:*
ESTAB 0 0 192.168.150.110:22 192.168.150.100:53233
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 :::22 :::*
對應netstat -antp
[root@centos7 tmp]# ss -antp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:*
users:(("master",1817,13))
LISTEN 0 128 *:22 *:*
users:(("sshd",1288,3))
ESTAB 0 0 192.168.150.110:22 192.168.150.100:59413
users:(("sshd",2299,3))
LISTEN 0 100 ::1:25 :::*
users:(("master",1817,14))
LISTEN 0 128 :::22 :::*
users:(("sshd",1288,4))
[root@centos7 tmp]#
看著真的很彆扭,不管多寬的終端屏,users:部分都會折到下一行,其實是在一行的。
格式化一下,內容整齊了,但是標題列串了:
[root@centos7 tmp]# ss -antp|column -t
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:* users:(("master",1817,13))
LISTEN 0 128 *:22 *:* users:(("sshd",1288,3))
ESTAB 0 0 192.168.150.110:22 192.168.150.100:59413 users:(("sshd",2299,3))
LISTEN 0 100 ::1:25 :::* users:(("master",1817,14))
LISTEN 0 128 :::22 :::* users:(("sshd",1288,4))
5、舊的network指令碼和ifcfg檔案
Centos7 開始,網路由 NetworkManager 服務負責管理,相對於舊的 /etc/init.d/network 指令碼,NetworkManager是動態、事件驅動的網路管理服務。舊的 /etc/init.d/network 以及 ifup,ifdown 等依然存在,但是處於備用狀態,即:NetworkManager運行時,多數情況下這些指令碼會調用NetworkManager去完成網路設定任務;NetworkManager麼有運行時,這些指令碼就按照老傳統管理網路。
[root@centos7 ~]# /etc/init.d/network start
Starting network (via systemctl): [ OK ]
注意(via systemctl)。
6、網路設定檔:
/etc/sysconfig/network 說是全域設定,預設裡面啥也沒有
/etc/hostname 用nmtui修改hostname後,主機名稱儲存在這裡
/etc/resolv.conf 儲存DNS設定,不需要手工改,nmtui裡面設定的DNS會出現在這裡
/etc/sysconfig/network-scripts/ 串連配置資訊 ifcfg 檔案
/etc/NetworkManager/system-connections/ VPN、移動寬頻、PPPoE串連