Linux network, x11vnc, virtualbox, useful commands.

Persistent config:
# vi /etc/network/interfaces
up route add -net 104.27.163.84 netmask 255.255.255.255 gw 192.168.68.1
down route del -net 104.27.163.84 netmask 255.255.255.255 gw 192.168.68.1

Generic method to add persistent static routing on Linux
# vi /etc/rc.local
Append the following line:
/sbin/ip route add 192.168.1.0/24 dev eth0
OR
/sbin/ip route add 192.168.1.0/24 dev eth0
OR
route add default gw 192.168.60.254

# vi /etc/rc.local
route add -net 104.0.0.0 netmask 255.0.0.0 gw 192.168.60.254

traceroute is a tool used to identify the path used by a packet to reach the destination. …
The traceroute command is available on most modern operating systems (Windows, Apple Mac OS, Unix, Linux, etc). traceroute usually works by sending a series of ICMP echo request packets to a destination.

1.ifconfig -a
cat /etc/resolv.conf œ‹ip/netmask/’Œdns
2.netstat -rn
3.cat /etc/sysconfig/network
4.cat /etc/sysconfig/network-scripts/ifcfg-eth0
5.traceroute
6.ip route show
7.route -n

Linux下清除DNS缓存
通常有的时候我们通过域名打不开网页,有可能使DNS缓存的原因(DNS解析的ip地址变了),解决办法如下:
方法一:$nslookup xxxx.com(这里是你要打开的域名)
方法二:$sudo /etc/init.d/nscd restart
或者:$service nscd restart
或者:$service nscd reload
如果nscd无法执行,先安装nscd,命令如下:$sudo apt-get install nscd

chmod a+rwx : set the last 3 octals to 777, so it ensure that Owner, Group and Users have the “rwx” set. If there was aditionnal bits in the first octal (setuid, setgid, and/or Sticky bit) it leaves them untouched.
There are three major types of file permissions:
User permissions. These permissions apply to a single user who has special access to the file. This user is called the owner.
Group permissions. These apply to a single group of users who have access to the file. This group is the owning group.
Other permissions. These apply to every other user on the system. These users are known as others, or the world.

You can do this:
1st way:
ls -l /path/to/file
the third field in the ls -l output is the user and the fourth is the group
2nd way:
stat /path/to/file

sudo chown notme:notmygroup myfile.txt
sudo chown -R myuser:mygroup otherfiles
The above command will change the ownership of every file, subdirectory, and subdirectory contents in otherfiles.

Linux: List all members of a group using /etc/group file
Use the grep command as follows:
$ grep ‘grpup-name-here’ /etc/group
$ grep ‘ftponly’ /etc/group
$ grep -i –color ‘ftponly’ /etc/group

GRUB 所使用的硬盘/分区命名约定与 Linux 使用的命名约定不同。在 Linux 中,第一个硬盘的第五个分区称作 “hda5″。而 GRUB 把这个分区称作 “(hd0,4)”。
调整当前 root 命令行,以使它指向保存 Linux 内核的分区。按以下格式输完命令,然后按 Enter 键:
grub> root (hd0,4)
可以在 GRUB 中使用它来引导 Linux 发行版,操作如下:
grub> root (fd0)
grub> kernel /boot/bzImage root=/dev/hda5 (将 /dev/hda5 更改成想要引导的分区名称)
grub> boot
一个简单的文本文件 menu.lst:
default 0
timeout 30
color white/blue blue/green

title=Boot Linux
root (hd0,4)
kernel /boot/bzImage root=/dev/hda5

title=Boot Linux using initrd
root (hd0,5)
kernel /boot/bzImage root=/dev/loop0 init=/initdisk.gz
initrd /initdisk.gz

title=Windows NT
root (hd0,3)
chainloader +1

然后修改boot.ini
操作系统文件(推荐),把前面的勾去掉,就可以了),在boot.ini最后添加一行:
C:\grldr=linux boot
grldr会搜索C盘根目录寻找menu.lst文件。
用记事本打开menu.lst,编辑内容如下:
color black/cyan yellow/cyan
timeout 5
default /default
title Red Hat Enterprise Linux Server (2.6.18-53.el5)
root (hd0,7)
kernel /boot/vmlinuz-2.6.18-53.el5 ro root=LABEL=/ rhgb quiet
initrd /boot/initrd-2.6.18-53.el5.img
boot

A jump server is an intermediary server through which external agents, such as Venafi Encryption Director, can access a device behind a firewall.
If a jump server is required to access a device behind a firewall, the Jump Server object provides the information Venafi Encryption Director needs to communicate with the target device(s) via the jump server.
Jump server may use either username and password or private key for authentication. The target device and application can’t use private key for authentication.

A jump server can be useful when it’s a sort of privileged access proxy. That is, I connect to it as a normal user, and it does whatever I ask it to using elevated privileges that only last for the duration of my stay.

To fix this problem you need to have another computer, which is publicly accessible and have SSH access to it. It can be any server on the internet, as long as you can connect to it.
We’ll tell SSH to make a tunnel that opens up a new port on the server, and connects it to a local port on your machine.
$ ssh -R 9000:localhost:3000 user@example.com
The syntax here is very similar to local port forwarding, with a single change of -L for -R. But as with local port forwarding, the syntax remains the same.
First you need to specify the port on which th remote server will listen, which in this case is 9000, and next follows localhost for your local machine, and the local port, which in this case is 3000.
There is one more thing you need to do to enable this. SSH doesn’t by default allow remote hosts to forwarded ports. To enable this open /etc/ssh/sshd_config and add the following line somewhere in that config file.
GatewayPorts yes

$ pgrep x11v -a
3446 x11vnc -gui tray=setpass -rfbport PROMPT -bg -o %HOME/.x11vnc.log.%VNCDISPLAY

$ ss -ltn
$ ss -ltp
$ netstat -ltn
$ netstat -ltp

Windows下的文字到了Linux下乱码原因是Windows中默认的文件格式是GBK(gb2312),而Linux一般都是UTF-8,编码格式不相同导致的乱码。几种解决办法如下:
1、在Windows上用记事本把文件,选择另存为编码方式改为 UTF-8;
2、在Linux上用vim编辑,在命令模式下输入:
:set fileencoding=utf-8
3、iconv 转换,iconv的命令格式如下:
iconv -f encoding -t encoding inputfile
#比如将一个GBK编码的文件转换成UTF-8编码
iconv -f UTF-8 -t GBK file1 -o file2
#转码后,在Linux上面就不会乱码了

install mongodb on ubuntu:
/usr/bin/mongod –unixSocketPrefix=/run/mongodb –config /etc/mongodb.conf
bind_ip is necessary, otherwise mongo doesn’t work.
bind_ip = 192.168.1.56 (local address)
#bind_ip = 127.0.0.1
#port = 27017
ufw allow 27017
sudo service mongodb stop | sudo service mongodb start

sudo apt-get install ifconfig
Error: unable to locate ifconfig
=> sudo apt install net-tools.

RealVNC Viewer vs tigerVNC viewer
Install openssh-server on MiniServer, allow port 22, then i can access it via ssh.

sudo apt-get install x11vnc
sudo x11vnc -storepasswd

sudo nano /lib/systemd/system/x11vnc.service
[Unit]
Description=Start x11vnc at startup.
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -once -loop -noxdamage -repeat -rfbauth /home/USERNAME/.vnc/passwd -rfbport 5900 -shared
[Install]
WantedBy=multi-user.target

$ sudo systemctl daemon-reload
$ sudo systemctl enable x11vnc.service
=>
$ x11vnc

#ss -ltn
#netstat -ltn
Remove the default Vino server:
sudo apt-get -y remove vino

Ubuntu Setting -> Share -> Enable RemoteDesktop. (Necessary?)
=> Then i can see port 5900 opened.

设置miwifi静态路由,miwifi.com高级设置里面

/etc/rc.local 不执行的问题汇总
查看/etc/rc.local是否有执行权限,没有就加上
#chmod +x /etc/rc.local
检查/etc/rc.local是文件还是软连接?
如果是文件,那么启动项就无法启动了,因为启动时调用/etc/rc.d/rc.local里面的指令
如果不是,修改步骤如下:
# rm -rf /etc/rc.local
# ln -s /etc/rc.d/rc.local /etc/rc.local

配置为跟随系统自动启动
新建文件/etc/init/x11vnc.conf
并写入如下内容
start on login-session-start
script
x11vnc -display :0 -auth /var/run/lightdm/root/:0 -forever -bg -o /var/log/x11vnc.log -rfbauth /etc/x11vnc.pass -rfbport 5900
x11vnc -display :0 -auth guess -once -loop -noxdamage -repeat -rfbauth /home/wtong/.vnc/passwd -rfbport 5900 -shared
end script

=>Still a problem.

$ sudo dpkg -L x11vnc

su为switch user,即切换用户的简写
su [user]切换到其他用户,但是不切换环境变量,su – [user]则是完整的切换到新的用户环境。
sudo是一种权限管理机制,依赖于/etc/sudoers,其定义了授权给哪个用户可以以管理员的身份能够执行什么样的管理命令;
sudo的配置文件为:/etc/sudoers。
sudoers文件中允许指定用户在不需要知道root用户的登陆密码的情况下,可以以root用户身份运行各种命令。此文件必须使用visudo命令编辑配置。

Error:
Add vitualbox source to APT sourcelist, then update.
$sudo apt-get update
Skipping acquire of configured file ‘contrib/binary-i386/Packages’ as repository
‘http://download.virtualbox.org/virtualbox/debian bionic InRelease’ doesn’t support architecture ‘i386’
=>
Edit:
sudo nano /etc/apt/sources.list.d/virtualbox.list
and change:
deb http://download.virtualbox.org/virtualbox/debian bionic contrib
for
deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian bionic contrib
Or open terminal an execute the following command:
echo “deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian $(lsb_release -sc) contrib” | sudo tee /etc/apt/sources.list.d/virtualbox.list
SOLUTION : limit to just 64 bit by introducing the [arch=amd64]

$ dpkg –print-architecture
amd64
$ lsb_release -cs
bionic

Install Virtualbox-5.2 on Ubuntu 1804
添加源可以保持更新:
$ sed -i ‘$adeb [arch=amd64] http://download.virtualbox.org/virtualbox/debian bionic contrib’ /etc/apt/sources.list
Or
$ sudo add-apt-repository “deb http://download.virtualbox.org/virtualbox/debian `lsb_release -cs` contrib”
deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian bionic contrib
# deb-src http://download.virtualbox.org/virtualbox/debian bionic contrib
为apt-secure导入公钥:
$ wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add –
$ wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add –
通过apt安装VirtualBox和dkms,其中dkms包可以确保在下次通过apt upgrade更新内核时,VirtualBox的内核模块也正确地更新:
$ sudo apt-get update
$ sudo apt-get install virtualbox-5.2

Download Centos Images:
https://www.centos.org/download/
4G DVD + 960M Minimal

$ sudo shutdown -P –no-wall 150
Shutdown scheduled for Thu 2018-12-06 10:44:27 CST, use ‘shutdown -c’ to cancel.

Install stress-ng on Debian and Ubuntu:
sudo apt-get install stress-ng

Hardinfo can be grabbed on most distros using the native package manager, but I find it easiest to just run this command on Debian and Ubuntu:
sudo apt-get install hardinfo

可以通过修改/etc/gdm/custom.conf文件,实现root用户免密码自动登陆
在[daemon]下增加
[daemon]
AutomaticLoginEnable=True
AutomaticLogin=root
保存文件,然后重启查看效果

# locate virtualbox | grep .iso
/usr/share/virtualbox/VBoxGuestAdditions.iso
点击 VirtualBox 菜单栏中的【设备】->【分配光驱】->【选择虚拟盘】->【定位到 VirtualBox 安装目录】->【选择 VBoxGuestAdditions.iso】,
这时可能会提示一些信息,不用理会,点击【强制释放】,不要点击【取消】
挂载光驱到 tmp 目录 !!! 核心步骤!!!
[root@localhost ~] mount /dev/cdrom /tmp/  # 这时会提示目录挂载成功且为ready-only
[root@localhost ~] cp -r /tmp/ /mnt/      # 把挂载目录复制到另外一个文件夹,这样才能执行写操作
修改/mnt/tmp/目录下所有文件为可写权限
[root@localhost ~] cd /mnt/tmp
[root@localhost tmp] ./VBoxLinuxAdditions.run  # 执行安装
提示安装成功,再重启系统,大功告成!
然后,就会发现其中的菜单项“Switch to Seamless Mode(虚拟显示屏)”可以使用了
点击“虚拟显示屏”菜单项,就可以选择需要的分辨率了

安装显卡驱动。
yum -y install kmod-fglrx
如果没有安装显卡驱动,安装了增强包后虚拟机中的CentOS不能自动根据窗口大小的改变而自动调整分辨率,只显示了两个分辨率:
1024*768 60Hz
800*600 60Hz

让隐藏的virtualBox菜单重新显示
首先进入虚拟机,然后按你的Host key+Home键,就会弹出菜单栏,然后选择Switch to scale mode,隐藏的菜单就会重新显示了。
如果你觉得这样有些麻烦,可以直接按Host key+C,也能达到同样的效果。

RedHat、RHEL:rpm -i vh *.rpm
Ubuntu安装:sudo dpkg -i *.deb

1、yum -y update
2、yum -y install g++ gcc gcc-c++ make kernel-* # 主要是在安装增强工具提示没有安装这些软件
3、yum -y install bzip2* # 增强工具用的是bzip2压缩

1、安装编译所需的依赖包
yum groupinstall “Development Tools”
2、安装内核开发包
yum install kernel-devel kernel-devel-3.10.0-957.el7.x86_64 (According to VBoxLinux…..run prompt)
yum install kernel-headers

./VBoxLinuxAdditions.run

Centos7修改网卡对应的配置文件,设置BOOTPROTO为dhcp,ONBOOT为yes
$ vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
ONBOOT=yes
修改网关,设置NETWORKING为yes,GATEWAY为VirtualBox虚拟网卡的ip地址
$ vi /etc/sysconfig/network
修改DNS,设置nameserver为host主机的nameserver
$ vi /etc/resolv.cof

$ tightvncserver -kill :1
$ tightvncserver

sudo apt-get install xfonts-100dpi
sudo apt-get install xfonts-75dpi
=>
NOT WORK for tightvncserver, so use back to x11vnc.
$ sudo apt-get purge tightvncserver

apt-get remove 会删除软件包而保留软件的配置文件
apt-get purge 会同时清除软件包和软件的配置文件


发表评论

电子邮件地址不会被公开。