网络

Ubuntu配置samba服务

首先必须安装samba:

# sudo apt install samba

创建samba用户:

# sudo smbpasswd -a root
# sudo vim /etc/samba/smb.conf

smb.conf配置文件添加如下内容:

[root]
    comment = share root file systems
    path = /
    valid user = root
    public = no
    writable = yes

重启samba服务:

# sudo service smbd restart

tcp抓包

抓取与本机交互的网络包,除了ssh协议包和arp协议包:

# sudo tcpdump -i enp0s3 -Avvvn 'host 192.168.0.117 and ! port 22 and ! arp'

抓取p2p网络发现包:

# sudo tcpdump -i enp0s3 -Avvvn 'udp and port 1900'

使用tcpdump抓包保存,使用wireshark分析包内容:

# sudo tcpdump -i enp0s3 -Avvvn 'port !22 and port !137 and port !138 and port !139  and host 192.168.0.178' -w ./target1.cap

然后将target1.cap取出使用wireshark分析包内容。

wireshark抓包

wireshark过滤条件(抓取179主机的包,过滤掉ssh和smb2协议):

(ip.addr == 192.168.0.178)  &&  !(tcp.port == 22) && !(smb2)

抓取192.168.0.107主机上udp包:

!smb2 and udp and !ip.addr == 192.168.0.107

抓取两个主机之间的所有包:

(ip.src == 192.168.0.177 and  ip.dst == 192.168.0.178) or (ip.src == 192.168.0.178 and ip.dst == 192.168.0.177)

curl

curl -i -v --trace \
     --user name:password \
     --cookie "name=xxx" \
     --user-agent "[User Agent]" \
     -X POST http://www.baidu.com \
     -H "Content-type: application/jsons" \
     -d "{'key1':123}"

wget

wget下载文件:

# wget  http://192.168.0.1:1900/igd.xml

ubuntu apt-get update 失败

当运行apt-get update后出现如下错误时:

E: Some index files failed to download, they have been ignored, or old ones used instead

执行:

# sudo apt-get clean

如果还是不能解决问题,则修改DNS:

# sudo vi /etc/resolvconf/resolv.conf.d/base

这个文件默认是空的,里面添加:

nameserver 8.8.8.8
nameserver 8.8.4.4

修改好保存,然后执行

# sudo resolvconf -u

再看/etc/resolv.conf,最下面就多了2行:

cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
nameserver 8.8.4.4

重新update即可解决。

Ubuntu不能ping通外网

方法一:

# sudo route add default gw 192.168.0.1

方法二:

sudo vim /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
nameserver 8.8.4.4

nameserver 192.168.0.1

重启网络服务:

# sudo service networking restart

ping外网可以ping通。

用nc作为TCP/UDP通信调试工具

  1. 调试TCP通信
    服务端监听:
    # nc -lk 5656
    

    客户端发送消息:

    # echo "====================" | nc 192.168.0.177 5656
    
  2. 调试UDP通信 服务端监听:
    # nc -4u -l -k  5657
    

    客户端发送消息:

    #  echo "====================" | nc -4u -w1 192.168.0.177 5657