Linux命令整理 - 通用版

通用版 - 系统架构

/dev    设备文件夹                       
        null    有去无回                    
        mouse                       
/sbin   系统管理必备程序                        
    cfdisk、dhcpcd、dump、e2fsck、fdisk、halt、ifconfig、ifup、 ifdown、init、insmod、lilo、lsmod、mke2fs、modprobe、quotacheck、reboot、rmmod、 runlevel、shutdown等。                      
/bin    系统必备执行文件                        
    cat、cp、chmod df、dmesg、gzip、kill、ls、mkdir、more、mount、rm、su、tar等。                         
/usr/bin    程序工具必备执行文件                      
            c++、g++、gcc、chdrv、diff、dig、du、eject、elm、free、gnome*、 gzip、htpasswd、kfm、ktop、last、less、locale、m4、make、man、mcopy、ncftp、 newaliases、nslookup passwd、quota、smb*、wget等。                      
/usr/sbin   网络管理必备程序                        
            dhcpd、httpd、imap、in.*d、inetd、lpd、named、netconfig、nmbd、samba、sendmail、squid、swap、tcpd、tcpdump等                       
/lib    共享库目录                       
    /systemd    系统脚本如shutdown/sleep    

通用版-常用系统命令

找出程序运行的端口 netstat -ap | grep '程序名' 
根据进程名查看pid    "pgrep -f nis --pid
pgrep -lo -f nis --pid + 进程详情"    
找出端口的程序名    netstat -ap | grep '端口号'    
查看端口-》关闭进程    netstat -apn | grep 8888 kill -9 PID 
显示路由表的信息    netstat -r    route    
列出所有的端口,包括监听的和未监听    netstat -a    
列出所有的tcp协议的端口    netstat -t    
列出所有的UDP协议的端口    netstat -ua    
路由器跟踪定位    traceroute IP    
查看端口pid    fuser -nv tcp 80    
连接 win 远程桌面    rdesktop -u username ip linux    
查看系统信息    file /lib/systemd/systemd  
系统软件更新 apt-get update & apt-get upgrade apt-get dist-upgrade
重启 reboot 改变用户所在用户组 usermod
-g bbu operator last命令 显示近期用户或终端的登录情况
ifconfig eth0 (-)promisc 设置网卡(混杂)模式 
sysctl -w net.ipv4.ip_forward=1 - 修改ip_forward


配置文件相关

sysctl.conf    
/sbin/sysctl -e -p /etc/sysctl.conf  #重启    
ifconfig
ifconfig eth0 (-)promisc 设置网卡(混杂)模式 


服务

查看端口对应服务
lsof -i tcp:22 

chronyd
systemctl stop chronyd 停止 systemctl disable chronyd 禁用
avahi
-daemon systemctl stop avahi-daemon 停止 chkconfig avahi-daemon off service avahi-daemon stop
/etc/init.d/avahi-daemon stop

cups
service cups stop 停止
ident FTP service vsftpd status 状态 service vsftpd stop 停止
dhcp
/etc/init.d/dhcpd stop
http service httpd stop

ntpd  - 操作系统Daemon进程,用于校正本地系统与Internet标准时钟源之间的时间。
service ntpd stop
service ntpd status

snmp - 获得路由器上的统计数据而约定好的数据交流的规则
service snmpd stop 


文件操作

echo "123" > 1.txt    写文件    
file filename    查文件类型    


ps命令

-ef    
字段含义如下:    
UID       PID       PPID      C     STIME    TTY       TIME         CMD    
zzw      14124   13991      0     00:38      pts/0      00:00:00    grep --color=auto dae    
UID      UID 所拥有    
PID      程序的 ID     
PPID    上级父程序的ID    
C      CPU使用的资源百分比    
STIME    系统启动时间    
TTY     登入者的终端机位置    
TIME       使用掉的CPU时间。    
CMD      指令    
View Code


DNSmasq  -  用于DNS和DHCP配置/适用于小型网络(个人用户或主机少于50台)

---DNS服务器搭建  - coredns    

memcached

/etc/init.d/memcached restart/stop

mongodb

ps -ef | grep mongo sudo kill  74316(pid)
安装:mongod --dbpath "C:\mongodb\db" --logpath "C:\mongodb\log.txt" --install --serviceName "MongoDB"
卸载:mongod.exe --remove --serviceName "MongoDB"

ssh

安装
sudo apt-get install openssh-server 
ps -e | grep ssh    
/etc/init.d/ssh start    
sudo /etc/init.d/ssh resart 
配置文件    /etc/ssh/sshd_config
允许root用户远程登录    PermitRootLogin参数值为yes

iptalbes

iptables 重启防火墙失败 service iptables restart
systemctl restart iptables.service

指定IP访问指定端口
iptables 限制ip访问
通过iptables限制9889端口的访问(只允许192.168.1.201、192.168.1.202、192.168.1.203),其他ip都禁止访问
iptables -I INPUT -p tcp --dport 9889 -j DROP
iptables -I INPUT -s 192.168.1.201 -p tcp --dport 9889 -j ACCEPT
iptables -I INPUT -s 192.168.1.202 -p tcp --dport 9889 -j ACCEPT
iptables -I INPUT -s 192.168.1.203 -p tcp --dport 9889 -j ACCEPT

nginx

重启 service nginx restart
启动 nginx -c /usr/local/nginx/conf/nginx.conf
停止 nginx -s stop
卸载 nginx -s reload
posted @ 2019-07-02 15:18  7hang  阅读(327)  评论(0编辑  收藏  举报