1.在网络接口配置文件中(ifcfg-ethN),最多可以配置三个DNS选项(DNS1, DNS2, DNS3)
2.ifconfig – configure a network interface
(1). 显示所有网卡的配置信息
ifconfig
#or
ifconfig -a
(if a single -a argument is given, it displays the status of all interfaces)
(2). 显示eth0的配置信息
ifconfig eth0
(3). 配置网卡的地址
ifconfig eth0 192.168.1.23 netmask 255.255.255.0 up
(4). 打开/关闭网卡
ifconfig eth0 down && ifconfig eth0 up
或
ifdown eth0 && ifup eth0
(5). 设置MTU
ipconfig eth0 mtu 2000
或
echo “1499” > /sys/class/net/echo/mtu
(6). 为网卡添加另一个IP地址
ifconfig eth0:2 192.168.3.1 netmask 255.255.255.0 up
Continue reading
Category Archives: Linux
Linux网络配置点滴
DHCPD服务配置
DHCP(Dynamic Host Configuration protocol, DHCP) 是一个局域网的网络协议,使用UDP进行数据传输(服务器UDP端口67,客户端UDP端口 68)。主要功能是将内部网络或ISP的IP资源分配给用户。DHCP通常配置在网关路由器或者三成交换机上,也可以配置在服务器上。
DHCP运行分为四个步骤:
(1). 请求IP租约(discover)
客户端采用广播的形式去寻找DHCP服务器。如果这个网段内有多个DHCP服务器,那么最先响应的DHCP服务器将先进行DHCP服务。
(2). 提供IP租约(offer)
DHCP在地址池中挑选一个未被使
用的IP地址给客户端使用。
(3). 选择IP租约(request)
当客户端收到一个IP租约提供时,它必须广播来所有DHCP服务器它已经接受了一个租约offer。因此,该客户会发送一个DHCPREQUEST消息,其中包含提供租约的服务器的IP。当其他DHCP服务器收到了该消息后,它们会收回该的租约。并将IP地址重新放回到可用地址池中。
(4). 确认IP租约(ack)
当DHCP服务器收到来自客户端的DHCPREQUEST消息后,它就开始了配置过程的最后阶段。这个响应阶段包括发送一个DHCPACK包给客户。这个包包含租期和客户可能请求的其他所有配置信息(如DNS服务器等)
Continue reading
配置iSCSI target和initiator
1. 概念
iSCSI是在IP网络上传输的SCSI协议的存储技术,iSCSI的存储叫做 IP-SAN。
一个重要的概念是iqn(iSCSI Qualified Name)。iqn 格式:iqn.
iSCSI target端是iscsi存储服务器.target端一般为盘阵主机或者共享磁盘的主机,默认提供服务的端口是3260;
iSCSI initiator端是挂接 iscsi 的节点
Continue reading
逻辑卷的扩展和收缩
LVM(logical volume)的一个重要的功能就是可以随意扩展和收缩分区的大小。下面简单模拟这两种情形。
Continue reading
Linux时区和NTP服务配置
首先设置时区:
将对应时区文件拷贝一个副本为/etc/localtime
1 |
<SHELL># cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime |
RHEL6 Server Security Hardening
# For RHEL 6/OEL 6/CentOS 6.
1. disabling services
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
chkconfig NetworkManager off chkconfig abrt-ccpp off chkconfig abrtd off chkconfig acpid off chkconfig atd off chkconfig bluetooth off chkconfig certmonger off chkconfig cpuspeed off chkconfig cgconfig off chkconfig cpuspeed off chkconfig ip6tables off chkconfig iptables off chkconfig libvirt-guests off chkconfig netconsole off chkconfig netfs off chkconfig nfslock off chkconfig postfix off chkconfig rpcgssd off chkconfig rpcidmapd off chkconfig rhnsd off chkconfig restorecond off chkconfig httpd off chkconfig vsftpd off |
2. ntp client
1 2 |
#crontab -e 38 * * * * /usr/sbin/ntpdate 172.18.5.193 >>/root/ntpdate.log 2>&1 |
3. global env varaiables
1 2 3 4 5 |
vim /etc/profile # adding. export TZ=Asia/Shanghai export TMOUT=1800 comment if-clause of umask statement,and use 'umask 022' to replace it. |
4. use PAM
1 2 3 4 5 6 7 8 9 |
vim /etc/pam.d/su: auth sufficient pam_rootok.so # Uncomment the following line to implicitly trust users in the "wheel" group. # auth sufficient pam_wheel.so trust use_uid # Uncomment the following line to require a user to be in the "wheel" group. auth required pam_wheel.so use_uid # only users in wheel group can su to root # you can modify user to wheel group like this: usermod -G10 username # then check: /etc/groups |
5. password policy
1 2 3 4 5 6 |
(1)/etc/pam.d/passwd password include system-auth (2)修改文件/etc/pam.d/system-auth password requisite pam_cracklib.so minlen=8 lcredit=-1 ucredit=-1 dcredit=-1 ocredit=-1 # minlen the length of password # lcredit ucredit dcredit ocredit表示小写、大写、数字、符合,设定值为为负数如-1表示至少1个,为正数如3表示最多3个 |
6. create user without creating home
1 2 3 |
/etc/login.defs CREATE_HOME no UMASK 027 |
7. /etc/ssh/sshd_config
1 2 3 |
PermitRootLogin no MaxAuthTries 3 MaxSessions 5 |
8. lock accounts
需要锁定的账号:adm、lp、sync、shutdown、halt、mail、news、uucp、operator、games、gopher、ftp、mailnull、
nfsnobody、nobody、pegasus、http
参考配置
(1)删除用户:#userdel username;
(2)锁定用户:#passwd -l username
(3)解锁用户:#passwd -u username
(4)禁止用户交互登录:修改/etc/passwd文件,用户shell修改为/sbin/nologin
补充说明
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
passwd -l adm passwd -l lp passwd -l sync passwd -l shutdown passwd -l halt passwd -l mail passwd -l news passwd -l uucp passwd -l operator passwd -l games passwd -l gopher passwd -l ftp passwd -l mailnull passwd -l nfsnobody passwd -l nobody passwd -l pegasus passwd -l http |
9. banner
1 2 3 4 5 |
#vim /etc/motd Authorized users only.All activities will be monitored and reported. #vim /etc/vsftpd/vsftpd.conf ftpd_banner="Authorized users only.All activity may be monitored and reported." anonymous_enable=NO |
10. disable Control-Alt-Delete
修改/etc/init/control-alt-delete.conf文件,注释如下内容:
1 |
exec /sbin/shutdown -r now "Control-Alt-Delete pressed" |
11. syslog
1 2 3 4 5 6 7 |
#vim /etc/rsyslog.conf *.err;kern.debug;daemon.notice; /var/log/messages authpriv.* /var/log/secure(已经有了,确定一下) 重启syslog服务 /etc/init.d/rsyslog restart 修改log目录权限 #chmod 640 -R /var/log/ |
【APUE】UNIX下的文件操作
1. 内核文件数据结构
内核使用三种数据结构表示打开的文件,它们之间的关系决定了在文件共享方面一个进程对另一个进程的影响。
(1). 每个进程在进程表中都一个记录项(task_struct),包含一个打开文件描述符表(存放在用户空间)。每个文件描述符为表中一项,包括文件描述符标识和指向一个文件表项的指针。
(2). 内核为所有打开文件维持一张文件表,每个文件表项包括:
a). 文件状态标识(RD, WR, APPEND, 同步和非阻塞等)。注意,文件描述符作用域是一个进程,而文件状态标识则适用于指向文件表中该表项的所有进程的描述符。使用fcntl函数来修改这两个结构。下面第3节将会解释。
b). 当前文件偏移量
c). 指向该文件v节点表项的指针。
(3). 每个打开文件或设备都有一个v-node结构,包含文件类型和对此文件进行各种操作的函数的指针。对于大多数文件,v-node还包含了该文件的i-node节点(i-node包含文件所有者、长度、所在设备、指向文件数据库在磁盘上位置的指针等)。这些信息是打开文件时从磁盘读入内存的,所以所有关于文件的信息都是快速可以使用的。
Linux没有使用v-node,而是使用了通用的i-node节点结构。虽然两者实现有所不同,但在概念上,v-node和i-node是一样的,都指向文件系统相关的i-node结构。
Continue reading
Linux查看文件系统信息的命令
1. stat命令
display file or file system status
[OPTIONS]
-L, –dereference: follow links
-f, –file-system: display file system status instead of file status
for example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$stat -f / File: "/" ID: 226bbf67f89f2919 Namelen: 255 Type: ext2/ext3 Block size: 4096 Fundamental block size: 4096 Blocks: Total: 13166733 Free: 11754278 Available: 11085427 Inodes: Total: 3350528 Free: 3148391 $stat /usr/binzip File: "zip" Size: 192376 Blocks: 376 IO Block: 4096 普通文件 Device: 805h/2053d Inode: 394634 Links: 1 Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2011-07-19 20:16:56.993522058 +0800 Modify: 2010-12-13 19:41:58.000000000 +0800 Change: 2011-06-04 09:13:15.072502606 +0800 |
UNIX文件信息
1. stat, fstat和lstat
stat, fstst, lstat – get file status
1 2 3 4 5 6 7 |
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> int stat(const char *path, struct stat *buf); int fstat(int fd, struct stat *buf); int lstat(const char *path, struct stat *buf); |
stat() stats the file pointed to by path and fills in buf. lstat() is identical to stat(), except that if path is a sym‐bolic link, then the link itself is stat-ed, not the file that is refers to.
fstat() is identical to stat(), except that the file to be stated is specified by the file descriptor fd.
Continue reading
UNIX进程环境和动态链接
1. 环境表
每个程序都会从父进程那里接收一张环境表。和参数包一样,环境表也是一个字符指针数组,其中每个指针包含你一个null结束的C字符串地址。全局变量environ则包含该指针数组地址,称为环境指针。环境指针指向环境表,保存每个环境字符串的地址。每个环境字符串都是name=value的形式。可以用getenv和putenv来访问特定的环境标量。
extern char **environ;
环境指针—–> 环境表:
environ—–> 环境字符串地址—–> HOME=/home/luffy
环境字符串地址—–> PATH=:/bin:/usr/bin
环境字符串地址—–> SHELL=/bin/bash
环境字符串地址—–> USER=luffy
环境字符串地址—–> LOGNAME=luffy
Continue reading