# 如何對CentOS進行聯網
1:以root管理的身份登錄系統
2:進入文件中
[root@localhost ~]# cd / [root@localhost /]# ls /etc/sysconfig/network-scripts ifcfg-ens33 ifdown-isdn ifup ifup-plip ifup-tunnel ifcfg-lo ifdown-post ifup-aliases ifup-plusb ifup-wireless ifdown ifdown-ppp ifup-bnep ifup-post init.ipv6-global ifdown-bnep ifdown-routes ifup-eth ifup-ppp network-functions ifdown-eth ifdown-sit ifup-ib ifup-routes network-functions-ipv6 ifdown-ib ifdown-Team ifup-ippp ifup-sit ifdown-ippp ifdown-TeamPort ifup-ipv6 ifup-Team ifdown-ipv6 ifdown-tunnel ifup-isdn ifup-TeamPort [root@localhost /]# vim /etc/sysconfig/network-scripts/ifcfg-ens333:進入文件中修改內容
# 修改下方兩個參數的內容 # BOOTPROTO=dhcp # ONBOOT=yes TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=dhcp DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens33 UUID=e0a357cb-fbf1-4a22-ad8e-86ede6a9f5f7 DEVICE=ens33 ONBOOT=yes4:輸入以下內容
[root@localhost /]# service network restart Restarting network (via systemctl):5:可嘗試ping百度
t@localhost /]# ^C [root@localhost /]# pint www.baidu.com
6:退出ping,ctrl + c
# ssh
什么是ssh:SSH為Secure Shell的縮寫,由 IETF 的網絡小組(Network Working Group)所制定;SSH 為建立在應用層基礎上的安全協議。SSH 是目前較可靠,專為遠程登錄會話和其他網絡服務提供安全性的協議。利用 SSH 協議可以有效防止遠程管理過程中的信息泄露問題。
ssh的功能:傳統的網絡服務程序,如:ftp、pop和telnet在本質上都是不安全的,因為它們在網絡上用明文傳送口令和數據,別有用心的人非常容易就可以截獲這些口令和數據。而且,這些服務程序的安全驗證方式也是有其弱點的, 就是很容易受到“中間人”(man-in-the-middle)這種方式的攻擊。所謂“中間人”的攻擊方式, 就是“中間人”冒充真正的服務器接收你傳給服務器的數據,然后再冒充你把數據傳給真正的服務器。服務器和你之間的數據傳送被“中間人”一轉手做了手腳之后,就會出現很嚴重的問題。通過使用SSH,你可以把所有傳輸的數據進行加密,這樣"中間人"這種攻擊方式就不可能實現了,而且也能夠防止DNS欺騙和IP欺騙。使用SSH,還有一個額外的好處就是傳輸的數據是經過壓縮的,所以可以加快傳輸的速度。SSH有很多功能,它既可以代替Telnet,又可以為FTP、PoP、甚至為PPP提供一個安全的"通道"
(以上內容來自百度百科)
# 在每個linux服務器中都有ssh客戶端軟件和ssh服務端軟件
[root@localhost 桌面]# rpm -qa |grep openssh openssh-askpass-5.3p1-117.el6.x86_64 openssh-5.3p1-117.el6.x86_64 openssh-clients-5.3p1-117.el6.x86_64 # 客戶端軟件 openssh-server-5.3p1-117.el6.x86_64 # 服務端軟件
# 在上方提到,ssh最常見的用途就是用來進行遠程登錄,在進行遠程的登錄時我們得先獲得服務端 ip 地址
利用 ifconfig來獲得ip地址
[root@localhost ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:81:15:02 inet addr:192.168.37.135 Bcast:192.168.37.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe81:1502/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:13 errors:0 dropped:0 overruns:0 frame:0 TX packets:13 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1775 (1.7 KiB) TX bytes:1569 (1.5 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:16 errors:0 dropped:0 overruns:0 frame:0 TX packets:16 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:960 (960.0 b) TX bytes:960 (960.0 b)
# 可以利用常用的遠程管理工具xshell來進行遠程管理
注:xshell安裝方法

https://blog.csdn.net/pingqiwei/article/details/78502144
# 遠程鏈接
1)輸入ip地址
[D:\~]$ ssh 192.168.37.135
# ssh配置文件
[root@localhost 桌面]# vim /etc/ssh/sshd_config 文件中的#Port 22 # 為端口號
# 怎么解決ssh連接比較慢
在vim /etc/ssh/sshd_config打開的文件中找到 UseDNS no 除去注釋 將值改為no,表示連接時不進行dns解析
# 添加一個連接快捷方式
1:文件->新建
# 部署服務的步驟
1:准備環境
1)關閉防火牆
# 查看防火牆狀態: [root@centos6 ~]# service iptables status iptables:未運行防火牆。 # 開啟防火牆: [root@centos6 ~]# service iptables start # 關閉防火牆: [root@centos6 ~]# service iptables stop2)關閉selinux:SELINUX=disabled
# 打開配置文件 [root@localhost 桌面]# vim /etc/selinux/config # 修改以下內容 # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled //修改該行 # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted3)配置ip地址
# 查看是否配置ip [root@localhost ~]# ifconfig
...
2:安裝軟件包
[root@localhost ~]# yum install httpd -y
3:修改配置文件
# 打開配置文件 [root@localhost ~]# vim /etc/httpd/conf/httpd.conf Listen 80 # 監聽80端口 DocumentRoot "/var/www/html" # 文檔根目錄所在的位置,網站根目錄(當chrome瀏覽器向服務器發起請求,該網站就會到自己的DocumentRoot "/var/www/html"根目錄下找到該文件) # 在根目錄下添加一個測試文件 [root@localhost ~]# cd /var/www/html/ [root@localhost html]# ls [root@localhost html]# touch a.txt [root@localhost html]# echo "hello world" hello world [root@localhost html]# echo "hello world" > a.txt
4:重啟服務
[root@localhost html]# service httpd restart
5:測試
# 可在瀏覽器中輸入 https://www.doaoao.com/ 但不能進行訪問,因為DNS服務器不能將其解析成ip地址(本機中的服務器不知道將該域名翻譯成什么ip地址)
# 正確的訪問方式:瀏覽器中輸入:http://192.168.37.135:80/a.txt 訪問"/var/www/html"根目錄下得文件
# 注
當在瀏覽器輸入網址時,若不寫文件,默認訪問的是index.html,默認網站訪問文件 http://192.168.37.135/ 默認訪問的是index.html
[root@localhost html]# pwd /var/www/html [root@localhost html]# echo '默認頁面' > index.html [root@localhost html]# ls a.txt index.html
# 修改主機名稱
# 查看主機名稱
[root@localhost html]# hostname localhost.localdomain
# 修改主機名稱 [root@localhost html]# hostname www.doaoao.com
# 修改文件中的解析路徑 [root@localhost html]# vim /etc/hosts [root@localhost html]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.37.135 www.doaoao.com [root@localhost html]# service httpd restart 停止 httpd: [確定] 正在啟動 httpd: [確定] [root@localhost html]# hostname www.doaoao.com
samba是一個網絡服務器,用於Linux和windows之間共享文件
1:准備環境
1)關閉防火牆
2)關閉selinux
3)配置ip地址
2:安裝軟件包
[root@www ~]# yum install samba -y
3:修改配置文件
[root@www ~]# vim /etc/samba/smb.conf 配置文件中的內容: Scurity can be set to user, share(deprecated) or server(deprecated) security = share # 改成共享模式 passdb backend = tdbsam user :用戶訪問samba時需要密碼 share:用戶訪問samba時不需要密碼(共享模式)
4:重啟服務
[root@www ~]# service smb restart
5:測試
1)打開計算機->映射網絡驅動器
2)輸入對應的ip地址
\\192.168.37.137\company
\\service\share # server:ip地址 share:path指向的目錄名稱3)當出現問題時(報錯)
控制面板->程序->程序和功能->啟用或關閉Windows功能->(圖片映射網絡出現錯誤)
4)在windows上可以增加刪除文件
[root@www ~]# ll -d /company drwxr-xr-x 2 root root 4096 1月 24 19:52 /company [root@www ~]# chmod o+w /company/ # 讓windows具有操作文件的權限 當在配置文件中設置printable = yes 不能正常訪問文件(不顯示)
# 共享文件夾的定義
#============================ Share Definitions ============================== [homes] comment = Home Directories browseable = no writable = yes ; valid users = %S ; valid users = MYDOMAIN\%S [printers] comment = All Printers path = /var/spool/samba browseable = no guest ok = no writable = no printable = yes
# 添加一個samba用戶
# 添加一個samba用戶 [root@www company]# useradd doaoao useradd:用戶“doaoao”已存在 [root@www company]# smbpasswd -a doaoao New SMB password: Retype new SMB password: Added user doaoao. [root@www company]# # 網絡映射 \\192.168.37.135\doaoao # 直接加上用戶名
# 補查看系統日志 tail -f /var/log/messages
[root@www company]# tail -f /var/log/messages Jan 24 21:03:21 localhost ntpd[2325]: 0.0.0.0 0613 03 spike_detect +0.267876 s Jan 24 21:04:34 localhost dhclient[3165]: DHCPREQUEST on eth0 to 192.168.37.254 port 67 (xid=0x465eb448) Jan 24 21:04:34 localhost dhclient[3165]: DHCPACK from 192.168.37.254 (xid=0x465eb448) Jan 24 21:04:34 localhost NetworkManager[1997]: <info> (eth0): DHCPv4 state changed renew -> renew Jan 24 21:04:34 localhost NetworkManager[1997]: <info> address 192.168.37.135 Jan 24 21:04:34 localhost NetworkManager[1997]: <info> prefix 24 (255.255.255.0) Jan 24 21:04:34 localhost NetworkManager[1997]: <info> gateway 192.168.37.2 Jan 24 21:04:34 localhost NetworkManager[1997]: <info> nameserver '192.168.37.2' Jan 24 21:04:34 localhost NetworkManager[1997]: <info> domain name 'localdomain' Jan 24 21:04:34 localhost dhclient[3165]: bound to 192.168.37.135 -- renewal in 818 seconds.