telnet命令
telnet命令用於登錄遠程主機,對遠程主機進行管理。telnet因為采用明文傳送報文,安全性不好,很多Linux服務器都不開放telnet服務,而改用更安全的ssh方式了。但仍然有很多別的系統可能采用了telnet方式來提供遠程登錄,因此弄清楚telnet客戶端的使用方式仍是很有必要的。
語法
選項
參數
- 遠程主機:指定要登錄進行管理的遠程主機;
- 端口:指定TELNET協議使用的端口號。
實例
默認在centOS最小安裝下沒有安裝telnet服務的,需要自己安裝(root權限):
錯誤:
[root@localhost log] # telnet 192.168.10.56 27017 -bash : telnet: command not found1:查看系統版本信息(centos7):
[root@localhost log] # cat /etc/issue \S Kernel \r on an \ m2:檢查是否安裝telnet:
[root@localhost log] # rpm -qa | grep telnet [root@localhost log] #3:進行安裝,客戶端和服務器端:
[root@localhost xinetd.d] # yum -y install telnet Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile …………………… Verifying : 1:telnet-0.17-59.el7.x86_64 1/1 Installed: telnet.x86_64 1:0.17-59.el7 Complete! [root@localhost xinetd.d] # yum -y install telnet-server Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile …………………… Verifying : 1:telnet-server-0.17-59.el7.x86_64 1/1 Installed: telnet-server.x86_64 1:0.17-59.el7 Complete!注:如果安裝telnet-server服務啟動依賴xinetd服務.xinetd超級服務為管理保護各個服務,未安裝,需要首先按照。
xinetd:eXtended InterNET services daemon,超級Internet服務器,常用來管理多種輕量級Internet服務。
4:查看是否安裝xinetd (若安裝則不安裝):
[root@localhost ~] # rpm -qa | grep xinetd [root@localhost ~] #5:安裝xinetd服務:
[root@localhost init.d] # yum -y install xinetd Loaded plugins: fastestmirror base | 3.6 kB 00:00: 00 …………………… Verifying : 2:xinetd-2.3.15-12.el7.x86_64 1/1 Installed: xinetd.x86_64 2:2.3.15-12.el7 Complete!xinetd安裝完成!
6:telnet服務之后,默認是不開啟服務,修改文件/etc/xinetd.d/telnet來開啟服務:
注:如有則修改,第一次修改,此文件若不存在,可自己vim創建修改:
修改 disable = yes 為 disable = no
[root@localhost xinetd.d] # pwd /etc/xinetd.d [root@localhost xinetd.d] # ls chargen-dgram chargen-stream daytime-dgram daytime-stream discard-dgram discard-stream echo-dgram echo-stream tcpmux-server time-dgram time-stream [root@localhost xinetd.d] # vim telnet [root@localhost xinetd.d] # cat telnet修改后的telnet文件為:
# default: yes # description: The telnet server servestelnet sessions; it uses \ # unencrypted username/password pairs for authentication. service telnet { flags = REUSE socket_type = stream wait = no user = root server =/usr/sbin/in.telnetd log_on_failure += USERID disable = no }7:安裝后檢查:
[root@CentOS-Slave1 xinetd.d] # rpm -qa | grep telnet telnet-0.17-59.el7.x86_64 telnet-server-0.17-59.el7.x86_64 [root@CentOS-Slave1 xinetd.d] # rpm -qa | grep xinetd xinetd-2.3.15-12.el7.x86_648:啟動telnet和依賴的xinetd服務:
在centos7之前:
$ service xinetd restart 或$ /etc/rc.d/init.d/xinetd restart在centos7中(無xinetd的service啟動項):
[root@CentOS-Slave1 xinetd.d] # service xinetd restart Redirecting to /bin/systemctl restart xinetd.service [root@CentOS-Slave1 xinetd.d] # systemctl restart xinetd.service或
[root@CentOS-Slave1 xinetd.d]# /bin/systemctl restart xinetd.service
9:查看啟動:
[root@CentOS-Slave1 xinetd.d] # ps -ef | grep xinetd root 6641 1 0 23:22 ? 00:00:00 /usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid root 6644 5817 0 23:24 pts/3 00:00:00 grep --color=auto xinetd10:測試telent,輸入ip+用戶名+密碼登陸,登陸問題見備注附件:
[root@CentOS-Slave1 pam.d] # telnet 192.168.10.56 Trying 192.168.10.56... Connected to 192.168.10.56. Escape character is '^]'. Kernel 3.10.0-229.el7.x86_64 on an x86_64 CentOS-Slave1 login: root Password: Last failed login: Sat Oct 17 23:25:50 CST 2015 from CentOS-Slave1 on pts/ 0 There were 3 failed login attempts since the last successful login. Last login: Sat Oct 17 22:22:27 from CentOS-Slave1 [root@CentOS-Slave1 ~] # exit logout Connection closed by foreign host.11:設置服務開機啟動:
[root@CentOS-Slave1 rc3.d] # chkconfig --level 35 xinetd on Note: Forwarding request to 'systemctl enable xinetd.service'. [root@CentOS-Slave1 rc3.d] # systemctl enable xinetd.service12:查看:
[root@CentOS-Slave1 rc3.d] # chkconfig --list Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. mysql 0:off 1:off 2:on 3:on 4:on 5:on 6: off netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6: off network 0:off 1:off 2:on 3:on 4:on 5:on 6: off xinetd based services: chargen-dgram: off chargen-stream: off daytime-dgram: off daytime-stream: off discard-dgram: off discard-stream: off echo-dgram: off echo-stream: off tcpmux-server: off telnet: on time-dgram: off time-stream: off
備注附件:
問題1:telnet下root登錄,密碼正確,總提示:Login incorrect
解決1:注釋/etc/pam.d/remote的第一行,
即:auth required pam_securetty.so
[root@CentOS-Slave1 pam.d] # pwd /etc/pam.d [root@CentOS-Slave1 pam.d] # cat remote #%PAM-1.0 #telent 遠程root登陸允許 #auth required pam_securetty.so auth substack password-auth auth include postlogin ………………
問題2:其他機器遠程telnet的時候,登陸不成功,可能是防火牆的問題,修改防火牆的設置:注:netstat –tunlp查看是否23端口被防火牆封掉:
[root@CentOS-Slave1 pam.d] # netstat -tunlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 5891/./mongod tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 848/sshd tcp6 0 0 :::3306 :::* LISTEN 1997/mysqld tcp6 0 0 :::22 :::* LISTEN 848/sshd tcp6 0 0 :::23 :::* LISTEN 1/systemd再使用iptables修改設置,使用service iptables save保存設置,然后service iptables restart重啟防火牆:
iptables -I INPUT -p tcp --dport 23 -jACCEPT iptables -I INPUT -p udp --dport 23 -jACCEPT service iptables save //保存 service iptables restart //重啟防火牆問題new:[root@CentOS-Slave1 rc3.d]# chkconfig --level 35 xinetd on
Note: Forwarding request to 'systemctl enable xinetd.service'.
[root@CentOS-Slave1 xinetd.d]# service xinetd restart
Redirecting to /bin/systemctl restart xinetd.service解決new:
指令可以用,但是新版本系統,指令被(重新定向Redirecting/轉發Forwarding)到:
service xinetd restart ---> systemctl restart xinetd.service
chkconfig --level 35 xinetd on ---> systemctl enable sshd.service #對應為disable$.記住:以后控制服務就用這個指令。疑問3:telnet登陸主機后會提示Escape character is '^]':點擊提示的意思是按Ctrl + ] 會呼出telnet的命令行,就可以執行telnet命令:telnet命令:
#close關閉當前連接 #logout強制退出遠程用戶並關閉連接 #display顯示當前操作的參數 #mode試圖進入命令行方式或字符方式 #open連接到某一站點 #quit退出 #telnetsend發送特殊字符 #set設置當前操作的參數 #unset復位當前操作參數 #status打印狀態信息 #toggle對操作參數進行開關轉換 #slc改變特殊字符的狀態 #auth打開/關閉確認功能z掛起 #telnetenviron更改環境變量,顯示幫助信息iptables參數:linux運行級別
iptables [-AI 鏈名] [-io 網絡接口] [-p 協議] \ > [-s 來源IP/網域] [-d 目標IP/網域] -j [ACCEPT|DROP|REJECT|LOG] 選項與參數: -AI 鏈名:針對某的鏈進行規則的 "插入" 或 "累加" -A :新增加一條規則,該規則增加在原本規則的最后面。例如原本已經有四條規則, 使用 -A 就可以加上第五條規則! -I :插入一條規則。如果沒有指定此規則的順序,默認是插入變成第一條規則。 例如原本有四條規則,使用 -I 則該規則變成第一條,而原本四條變成 2~5 號 鏈 :有 INPUT, OUTPUT, FORWARD 等,此鏈名稱又與 -io 有關,請看底下。 -io 網絡接口:設定封包進出的接口規范 -i :封包所進入的那個網絡接口,例如 eth0, lo 等接口。需與 INPUT 鏈配合; -o :封包所傳出的那個網絡接口,需與 OUTPUT 鏈配合; -p 協定:設定此規則適用於哪種封包格式,主要的封包格式有: tcp, udp, icmp 及 all 。 -s 來源 IP/網域:設定此規則之封包的來源項目,可指定單純的 IP 或包括網域,例如:IP :192.168.0.100 網域:192.168.0.0/24, 192.168.0.0/255.255.255.0 均可。 若規范為『不許』時,則加上 ! 即可,例如:-s ! 192.168.100.0/24 表示不許 192.168.100.0/24 之封包來源; -d 目標 IP/網域:同 -s ,只不過這里指的是目標的 IP 或網域。 -j :后面接動作,主要的動作有接受(ACCEPT)、丟棄(DROP)、拒絕(REJECT)及記錄(LOG)
--------------------- 本文來自 TS_A1 的CSDN 博客 ,全文地址請點擊:https://blog.csdn.net/typa01_kk/article/details/46604967?utm_source=copy
chkconfig命令提供了一種簡單的方式來設置一個服務的運行級別,on和off分別指服務被啟動和停止。 運行級別就是操作系統當前正在運行的功能級別。級別是從0到6。 級別3和5上設定服務為“on” chkconfig --level 35 mysql on 其他級別上設為off chkconfig --level 01246 mysql off 列出服務將會運行的運行級別 #chkconfig --list mysql mysql 0:off 1:off 2:off 3:on 4:off 5:on 6 :off Linux下的7個運行級別: 0 :系統停機狀態,系統默認運行級別不能設置為0,否則不能正常啟動,機器關閉。 1 :單用戶工作狀態,root權限,用於系統維護,禁止遠程登陸,就像Windows下的安全模式 登錄。 2 :多用戶狀態,沒有NFS支持。 3 :完整的多用戶模式,有NFS,登陸后進入控制台命令行模式。 4 :系統未使用,保留一般不用,在一些特殊情況下可以用它來做一些事情。eg:在筆記本電腦的電池用盡時,可以切換到這個模式來做一些設置。 5 :X11控制台,登陸后進入圖形GUI模式,XWindow系統。 6 :系統正常關閉並重啟,默認運行級別不能設為6,否則不能正常啟動。運行init6機器就會重啟。 標准的Linux運行級別為3或5運行級別原理: 1 .在目錄/etc/rc.d/init.d下有許多服務器腳本程序,一般稱為服務(service) 2 .在/etc/rc.d下有7個名為rcN.d的目錄(N:0,1,2……),對應系統的7個運行級別 3 .rcN.d目錄下都是一些符號鏈接文件,這些鏈接文件都指向init.d目錄下的service腳 本文件,命名規則為K+nn+服務名或S+nn+服務名,其中nn為兩位數字。 4 .系統會根據指定的運行級別進入對應的rcN.d目錄,並按照文件名順序檢索目錄下的鏈接文件:對於以K(Kill)開頭的文件,系統將終止對應的服;對於以S(Start開頭的文件,系統將啟動對應的服務 5 .查看運行級別用:runlevel [root@CentOS-Slave1 pam.d] # runlevel N 3 [root@CentOS-Slave1 etc] # cd rc.d/ [root@CentOS-Slave1 rc.d] # ls init.d rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d rc.local [root@CentOS-Slave1 rc.d] # cd rc3.d/ [root@CentOS-Slave1 rc3.d] # ls K50netconsole S10network S64mysql [root@CentOS-Slave1 rc3.d] # pwd /etc/rc.d/rc3.d