Linux面试题(网络基础篇)

1、linux现连接一个新的存储(如 /dev/sdb,容量为200G)一人应用程序需要在 /data 目录使用此存储的100G的内存空间,若做成 LVM 需要哪些步骤,请描述

[root@localhost ~]# fdisk /dev/sdb   
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write the
m.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x10cd6a18.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-419430399, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-419430399, default 41
9430399): +100G
Partition 1 of type Linux and of size 100 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# pvcreate /dev/sdb1     //创建PV
Physical volume "/dev/sdb1" successfully created
[root@localhost ~]# vgcreate vgdata /dev/sdb1     //创建VG
Volume group "vgdata" successfully created
[root@localhost ~]# lvcreate -n lvdata -l 100%free vgdata     //创建LV
Logical volume "lvdata" created.
[root@localhost ~]# mkfs.ext4 /dev/vg   //下面的那条命令才是需要执行的,我在这里用了Tab键补全
vga_arbiter vgdata/
[root@localhost ~]# mkfs.ext4 /dev/vgdata/lvdata //要使用lvm就必须对lv进行格式化和挂载
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26213376 blocks
1310668 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2174746624
800 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost ~]# mount /dev/vgdata/lvdata /data/   //挂载
[root@localhost ~]# lsblk /dev/sdb   //查看
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 200G 0 disk
└─sdb1 8:17 0 100G 0 part
└─vgdata-lvdata 253:0 0 100G 0 lvm /data

2、打印 /etc/passwd 的 1 到 3 行

方法一:
[root@centos7 ~]# sed -n '1,3p' /etc/passwd
root:x:0:0:root:/root:/bin/bash
system:x:0:0::/home/system:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin

方法二:
[root@centos7 ~]# awk 'NR>=1&&NR<=3{print $0}' /etc/passwd   
root:x:0:0:root:/root:/bin/bash
system:x:0:0::/home/system:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin

3、用 sed 命令将指定的路径 /usr/local/http 替换成为 /usr/src/local/http

[root@centos7 ~]# echo "/usr/local/http/" | sed 's#/usr/local/#/usr/src/local/#'

4、打印 /etc/ssh/sshd_config 的第一百行

sed -n '100p' /etc/ssh/sshd_config

5、用 sed 命令永久关闭防火墙

[root@centos7 ~]# sed -i.bak 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config 
[root@centos7 ~]# cat /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 three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

7、快速查找 /root 目录中大于 2M 的文本,并将文件中的wang,换成www.wang.com

[root@centos6 ~]# dd if=/dev/zero  of=f1.txt bs=1M count=3
3+0 records in
3+0 records out
3145728 bytes (3.1 MB) copied, 0.0027172 s, 1.2 GB/s
[root@centos6 ~]# echo "wang" >> f1.txt 
[root@centos6 ~]# find /root/ -maxdepth 1 -type f -size +2M -exec sed -i 's/wang/www.wang.com/g' {} \;
[root@centos6 ~]# cat f1.txt 
www.wang.com

8、对 /etc/fstab 非#号开头的加注释

sed -r 's/(^[^#])/#&/' /etc/fstab

9、CentOS7 取 取 eno16777736 的 的 IP 地址

[root@centos7 ~]# ifconfig eno16777736 | sed -n 2p | sed -e 's/.*net //' -e 's/ net.*//'
172.16.251.191

10 、查看本机路由的三种方式

[root@centos6 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.220.0   0.0.0.0         255.255.255.0   U     1      0        0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
172.16.0.0      0.0.0.0         255.255.0.0     U     0      0        0 eth0
0.0.0.0         172.16.0.1      0.0.0.0         UG    0      0        0 eth0
[root@centos6 ~]# netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.220.0   0.0.0.0         255.255.255.0   U         0 0          0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
172.16.0.0      0.0.0.0         255.255.0.0     U         0 0          0 eth0
0.0.0.0         172.16.0.1      0.0.0.0         UG        0 0          0 eth0
[root@centos6 ~]#  ip route
192.168.220.0/24 dev eth1  proto kernel  scope link  src 192.168.220.157  metric 1 
169.254.0.0/16 dev eth0  scope link  metric 1002 
172.16.0.0/16 dev eth0  proto kernel  scope link  src 172.16.251.6 
default via 172.16.0.1 dev eth0  proto static 

11、发 4 个包,与 测试本机与 172.18.0.1 的连通性

 ping -c 4 -w 4 172.168.220.164

13 、分别提供 CentOS6 与 CentOS7

[root@centos7 ~]# hostname     //先查看一下原有主机名
centos7
[root@centos7 ~]# hostnamectl set-hostname centos7.9  //更改主机名(第一种方法)
[root@centos7 ~]# hostname     // 查看一下是否更改成功
centos7.9 
[root@centos7 ~]# hostname centos7   //更改主机名(第二种方# 法)
[root@centos7 ~]# hostname      //查看一下是否修改成功
centos7

上面是 centos7 修改主机名的两种方法;
下面我们来看 centos6 又是如何修改主机名的:

[root@centos6 ~]# hostname  //查看原有主机名一下
centos6
[root@centos6 ~]# hostname centos6.9   //更改主机名
[root@centos6 ~]# cat /etc/sysconfig/network  //查看一下配置文件是否修改成功
NETWORKING=yes
HOSTNAME=centos6.9

14、如何禁 ping

[root@node0 ~]# echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all  //这个时候,别人是可以 ping 通自己的
[root@node1 ~]# ping 192.168.6.6
PING 192.168.6.6 (192.168.6.6) 56(84) bytes of data.
64 bytes from 192.168.6.6: icmp_seq=1 ttl=64 time=1.79 ms
64 bytes from 192.168.6.6: icmp_seq=2 ttl=64 time=0.597 ms
[root@node0 ~]# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
[root@node1 ~]# ping 192.168.6.6    //ping 不能了
PING 192.168.6.6 (192.168.6.6) 56(84) bytes of data.
--- 192.168.6.6 ping statistics ---
93 packets transmitted, 0 received, 100% packet loss, time 92168ms

作者:六月天的安静
链接:https://www.jianshu.com/p/092bcf2f50fd
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 157,198评论 4 359
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,663评论 1 290
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 106,985评论 0 237
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,673评论 0 202
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 51,994评论 3 285
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,399评论 1 211
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,717评论 2 310
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,407评论 0 194
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,112评论 1 239
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,371评论 2 241
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,891评论 1 256
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,255评论 2 250
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,881评论 3 233
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,010评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,764评论 0 192
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,412评论 2 269
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,299评论 2 260

推荐阅读更多精彩内容