最近工作中遇到的linux的一些基本知识,总结一下。
1. 添加网卡,搭建虚拟网络
VM中可以在setting中自由添加/删除处理器、网卡等
2. Ipv6 主机ping命令: ping6
3. Ipv6地址配置:
(1) Ifconfig eth0 inet6 add 2001:100: :1 /64
(2) ip -6 addr add 2001:100::2/64 dev eth0
4. 设置静态ip: https://www.yaoblog.info/?p=4668
修改/etc/network/interfaces文件,然后重启
如下:
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet6 static
address 2001:100::2
netmask 64
allow-hotplug eth1
iface eth1 inet6 static
address 2001:1::1
netmask 64
up /sbin/ifconfig eth1 inet6 add fe80::211:22ff:fe33::4455/64
设置静态IP除了修改interfaces文件外,还可以通过图形界面,在network中设置,也可以使用ifconfig,但机器重启后失效。
5. 更改源:
编辑 /etc/apt/source.list文件,可以从网上搜一些源,覆盖原来的。(最好把原文件备份)
然后执行 sudo apt-get update
设置代理: 编辑/etc/apt/apt.conf文件,如
Acquire::http::Proxy "http://web-proxy.ind.com:8080";
6. Syslog的使用。在Ubuntu14.04中使用的是rsyslog
7. Telnet的使用
安装: sudo apt-get install telnetd
启动: sudo /etc/init.d/inetd restart
(Ubuntu14.04中,该文件不在相应位置,使用 find –name inetd命令查找文件位置)
8. 抓包工具: wireshark
9. wpa_supplicant
安装和配置dhcp-server
1. Get isc-dhcp-server package
sudo apt-get install isc-dhcp-server
2. Setup the inteface to enalbe DHCP server
sudo vi /etc/default/isc-dhcp-server
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACES="eth0"
3. Edit dhcpd.conf
sudo vi /etc/dhcp/dhcpd.conf
一个简单的范例:
default-lease-time 6000;
max-lease-time 72000;
option domain-name-servers 168.95.1.1;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.2 192.168.10.253;
option routers 192.168.1.254;
}
4. Restart DHCP server
sudo service isc-dhcp-server start
成功的话,会看到以下的信息,显示状态为running, 同时告知PID
isc-dhcp-server start/running, process 2631
Troubleshooting -- 察看syslog
sudo tail -f /var/log/syslog | grep dhcpd
11. Vim的配置:Ubuntu默认不带有vim, 需要安装。
sudo apt-get install vim
配置文件放在用户主目录下的.vimrc中。
http://www.cnblogs.com/ma6174/archive/2011/12/10/2283393.html
12. 共享文件夹位置: /mnt/hgfs/
13. 登录远程主机:ssh username@remot_ip
14. 远程主机和本机间传送文件:
scp -r local_folder remote_username@remote_ip:remote_folder
scp root@192.168.120.204:/opt/soft/nginx-0.5.38.tar.gz /opt/soft/
15. 很多命令的man文件可参考:
http://docs.oracle.com/cd/E56344_01/html/E54075/index.html
16. Ubuntu14.04 防火墙命令:
禁用防火墙: ufw disable
启动防火墙: ufw enable
Ufw default deny
查看状态: ufw status
其他系统上防火墙命令可以使用: service iptables start/stop/restart
17. 虚拟机系统的复制:
Move: MAC地址不变
Copy: MAC地址改变
18. Screen 的用法
Ubuntu安装screen: sudo apt-get install screen
常用命令:
显示所有键绑定信息;ctrl-a + ?
查看当前的screen: screen –ls
新建一个screen: screen –S name
恢复一个处于deattach状态的screen:screen –r name
在screen中保存退出: ctrl-a + d
创建窗口: ctrl- a + c
在screen之间切换: ctrl- a + n 或ctrl- a + p
输出screen的log: ctrl- a + H
第一次按下ctrl+a H,屏幕左下角会提示Creating logfile "screenlog.0".,开始记录日志。
再次按下ctrl+a H,屏幕左下角会提示Logfile "screenlog.0" closed.,停止记录日志。
Lock the screen: ctrl- a + x
终止退出screen: exit 或ctrl- a + k
重新启动 : restart screen(name)
删除dead 会话: screen –wipe
如果是attach状态,需要强制从终端分离,使用screen –d
19. 设置root密码
passwd username
20. ubuntu下允许root用户ssh远程登录
SSH服务器,可以通过SSH协议来访问远程服务器,代替telnet和ftp。但是ubuntu默认是不启用root用户也不允许root远程登录的。所以需要先启用root用户
启用root用户:sudo passwd root //修改密码后就启用了。
安装OpenSSH server:
1. 使用apt命令安装openssh server
$ sudo apt-get install openssh-server
2. 可以对 openssh server进行配置
$ sudo vi /etc/ssh/sshd_config
找到PermitRootLogin no一行,改为PermitRootLogin yes
3. 重启 openssh server
$ sudo service ssh restart
http://askubuntu.com/questions/449364/what-does-without-password-mean-in-sshd-config-file
21. 查看日志文件的某部分内容
某些服务默认记录在syslog中,如charon, dhcpd等,刚执行完命令,一般保存在文件的尾部。查看时可以使用命令: tail –f /var/log/syslog | grep dhcpd
或tail –f /var/log/syslog |grep charon
22. ls –alh
23. chmod a+ rwx *
24. 查看磁盘容量 df –hl
25. nm-tool 显示网关地址
26. mysql的使用:https://www.digitalocean.com/community/tutorials/a-basic-mysql-tutorial
http://www.yolinux.com/TUTORIALS/LinuxTutorialMySQL.html
install: apt-get install mysql-server
use database: mysqladmin -u root password 'new-password'
check database: SHOW DATABASES;
create a database: CREATE DATABASE database name;
access to a database: USE events; SHOW tables;
create a mysql table:
1. 添加网卡,搭建虚拟网络
VM中可以在setting中自由添加/删除处理器、网卡等
2. Ipv6 主机ping命令: ping6
3. Ipv6地址配置:
(1) Ifconfig eth0 inet6 add 2001:100: :1 /64
(2) ip -6 addr add 2001:100::2/64 dev eth0
4. 设置静态ip: https://www.yaoblog.info/?p=4668
修改/etc/network/interfaces文件,然后重启
如下:
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet6 static
address 2001:100::2
netmask 64
allow-hotplug eth1
iface eth1 inet6 static
address 2001:1::1
netmask 64
up /sbin/ifconfig eth1 inet6 add fe80::211:22ff:fe33::4455/64
设置静态IP除了修改interfaces文件外,还可以通过图形界面,在network中设置,也可以使用ifconfig,但机器重启后失效。
5. 更改源:
编辑 /etc/apt/source.list文件,可以从网上搜一些源,覆盖原来的。(最好把原文件备份)
然后执行 sudo apt-get update
设置代理: 编辑/etc/apt/apt.conf文件,如
Acquire::http::Proxy "http://web-proxy.ind.com:8080";
6. Syslog的使用。在Ubuntu14.04中使用的是rsyslog
7. Telnet的使用
安装: sudo apt-get install telnetd
启动: sudo /etc/init.d/inetd restart
(Ubuntu14.04中,该文件不在相应位置,使用 find –name inetd命令查找文件位置)
8. 抓包工具: wireshark
9. wpa_supplicant
安装和配置dhcp-server
1. Get isc-dhcp-server package
sudo apt-get install isc-dhcp-server
2. Setup the inteface to enalbe DHCP server
sudo vi /etc/default/isc-dhcp-server
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACES="eth0"
3. Edit dhcpd.conf
sudo vi /etc/dhcp/dhcpd.conf
一个简单的范例:
default-lease-time 6000;
max-lease-time 72000;
option domain-name-servers 168.95.1.1;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.2 192.168.10.253;
option routers 192.168.1.254;
}
4. Restart DHCP server
sudo service isc-dhcp-server start
成功的话,会看到以下的信息,显示状态为running, 同时告知PID
isc-dhcp-server start/running, process 2631
Troubleshooting -- 察看syslog
sudo tail -f /var/log/syslog | grep dhcpd
11. Vim的配置:Ubuntu默认不带有vim, 需要安装。
sudo apt-get install vim
配置文件放在用户主目录下的.vimrc中。
http://www.cnblogs.com/ma6174/archive/2011/12/10/2283393.html
12. 共享文件夹位置: /mnt/hgfs/
13. 登录远程主机:ssh username@remot_ip
14. 远程主机和本机间传送文件:
scp -r local_folder remote_username@remote_ip:remote_folder
scp root@192.168.120.204:/opt/soft/nginx-0.5.38.tar.gz /opt/soft/
15. 很多命令的man文件可参考:
http://docs.oracle.com/cd/E56344_01/html/E54075/index.html
16. Ubuntu14.04 防火墙命令:
禁用防火墙: ufw disable
启动防火墙: ufw enable
Ufw default deny
查看状态: ufw status
其他系统上防火墙命令可以使用: service iptables start/stop/restart
17. 虚拟机系统的复制:
Move: MAC地址不变
Copy: MAC地址改变
18. Screen 的用法
Ubuntu安装screen: sudo apt-get install screen
常用命令:
显示所有键绑定信息;ctrl-a + ?
查看当前的screen: screen –ls
新建一个screen: screen –S name
恢复一个处于deattach状态的screen:screen –r name
在screen中保存退出: ctrl-a + d
创建窗口: ctrl- a + c
在screen之间切换: ctrl- a + n 或ctrl- a + p
输出screen的log: ctrl- a + H
第一次按下ctrl+a H,屏幕左下角会提示Creating logfile "screenlog.0".,开始记录日志。
再次按下ctrl+a H,屏幕左下角会提示Logfile "screenlog.0" closed.,停止记录日志。
Lock the screen: ctrl- a + x
终止退出screen: exit 或ctrl- a + k
重新启动 : restart screen(name)
删除dead 会话: screen –wipe
如果是attach状态,需要强制从终端分离,使用screen –d
19. 设置root密码
passwd username
20. ubuntu下允许root用户ssh远程登录
SSH服务器,可以通过SSH协议来访问远程服务器,代替telnet和ftp。但是ubuntu默认是不启用root用户也不允许root远程登录的。所以需要先启用root用户
启用root用户:sudo passwd root //修改密码后就启用了。
安装OpenSSH server:
1. 使用apt命令安装openssh server
$ sudo apt-get install openssh-server
2. 可以对 openssh server进行配置
$ sudo vi /etc/ssh/sshd_config
找到PermitRootLogin no一行,改为PermitRootLogin yes
3. 重启 openssh server
$ sudo service ssh restart
http://askubuntu.com/questions/449364/what-does-without-password-mean-in-sshd-config-file
21. 查看日志文件的某部分内容
某些服务默认记录在syslog中,如charon, dhcpd等,刚执行完命令,一般保存在文件的尾部。查看时可以使用命令: tail –f /var/log/syslog | grep dhcpd
或tail –f /var/log/syslog |grep charon
22. ls –alh
23. chmod a+ rwx *
24. 查看磁盘容量 df –hl
25. nm-tool 显示网关地址
26. mysql的使用:https://www.digitalocean.com/community/tutorials/a-basic-mysql-tutorial
http://www.yolinux.com/TUTORIALS/LinuxTutorialMySQL.html
install: apt-get install mysql-server
use database: mysqladmin -u root password 'new-password'
check database: SHOW DATABASES;
create a database: CREATE DATABASE database name;
access to a database: USE events; SHOW tables;
create a mysql table:
27. du命令:统计目录中的文件的大小并以列表显示:
du [Path]
-a 全部文件 包括隐藏的。
-h 以M 为单位显示文件大小结果。
-s 统计此目录中所有文件大小总和。