What's the easiest way to test a gateway?

2019-08-28 01:23发布

I want to test a toy gateway I wrote. The testing will occur on Linux machines. I would like to do this in the easiest way possible, ideally writing no code and using existing utilities. This boils down to two questions:

  1. Is there an existing utility that can send packets with simple stuff in them(like a string that I supply) to a host through a user-specified gateway, without reconfiguring Linux's network settings? If so, what syntax would I use for the utility?

  2. Is there a simple utility I can run on the receiving end to verify that the correct packet was received? If so, what syntax would I use for the utility?

2条回答
\"骚年 ilove
2楼-- · 2019-08-28 02:04

The easiest would probably be the nc(1). Assuming your gateway IP is 192.168.1.1 and you are using TCP, then on the server, listening on port 8888:

~$ nc -k -l 8888

On the client:

~$ nc 192.168.1.1 8888
  your input
  ...
  ^C
查看更多
倾城 Initia
3楼-- · 2019-08-28 02:12

I don't know about the first, but I don't think it's that hard to modify your routing table:

route add -host 1.2.3.4 gw 5.6.7.8

(replace 1.2.3.4 by your target IP and 5.6.7.8 by the IP of your gateway).

For 2.: On the target server type netcat -l 1234 and on the client then type netcat 1.2.3.4 1234. (1234 is a "random" port number)(depending on your distribution netcat might be called simple "nc".) If a connection gets established you can just type data on the client or the server machine, press enter and see the data arriving on the other machine.

查看更多
登录 后发表回答