2.1 Simple Virtual Network 3 Network Simulation
Ethernet Networking Technology Guide  /  2 Tutorial  / 

2.2 Connect to a Real Network

A network simulation can also be connected to a real network. By doing this, simulated computers and real computers will be able to communicate with each other.

Note: Timing problems when using a real network connection, such as TCP timeouts, indicates that the simulation is running too fast: it might be idle most of the time. In this case, slow it down by using the enable-real-time-mode command.
Note: Connecting to a real network introduces potential security risks. See the Installation Guide for more information.
Before following the steps in this example, start a new firststeps.simics. By default, the firststeps.simics target script creates not only the target machine but also an Ethernet switch (the ethernet_switch0 object of the ethernet_switch class) and a kind of a router (the service_node_cmp0 object of the service_node_comp).

Once the target machine is booted, we can see that the simulated machine got IP address assigned. We use here newer ip command but the legacy ifconfig command is also available on the target:

~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq state UP group default qlen 1000
    link/ether 00:17:a0:00:00:00 brd ff:ff:ff:ff:ff:ff
    inet 10.10.0.100/24 brd 10.10.0.255 scope global dynamic enp0s25
       valid_lft 2998sec preferred_lft 2998sec
    inet6 11:2233:4455:6677:217:a0ff:fe00:0/64 scope global mngtmpaddr noprefixroute 
       valid_lft forever preferred_lft forever
    inet6 fe80::217:a0ff:fe00:0/64 scope link 
       valid_lft forever preferred_lft forever
~#

The IP address for the simulated machine was provided though DHCP service by the service_node_cmp0 object. The service_node_cmp0 object allows also to reach the outside world from the simulated machine:

~# curl -o index.html www.google.com
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 12419    0 12419    0     0   1566      0 --:--:--  0:00:07 --:--:--  3022
~#

Note: Corporate networks may require the use of proxies to connect to external resources. The simulated machine is not an exception. Thus, reaching external resource from the simulated machine may require additional configuration of the simulated machine.
Often, we would like to reach the simulated machine from the outside world. This can be done by configuring the service_node_cmp0 object to redirect accesses done to the simulation host ports to the simulated machine. To achieve this we will use the connect-real-network command. This command can set up a lot of things: create a new Ethernet switch, connect it to all simulated network devices as well as to the real network. In our case most of the things were already set up by the firststeps.simics target script so the command will just instruct the service_node_cmp0 object to forward ports 4021, 4022, 4023 and 4080 on the simulation host to the simulated machine's telnet, SSH, FTP and HTTP ports, respectively.

simics> connect-real-network
NAPT already enabled.
Host TCP port 4021 -> 10.10.0.100:21
Host TCP port 4022 -> 10.10.0.100:22
Host TCP port 4023 -> 10.10.0.100:23
Host TCP port 4080 -> 10.10.0.100:80

Note: Note that connect-real-network found out which IP address to work with by checking configuration variables set by firststeps.simics. You can also specify this address as parameter to the command
Since connect-real-network has set up forwarding for the ssh, telnet, FTP and HTTP ports of the simulated machine, it is possible to login to the simulated machine with ssh command. On your host, try the following:

host~$ ssh -p 4022 -l root localhost
The authenticity of host '[localhost]:4022 ([127.0.0.1]:4022)' can't be established.
ECDSA key fingerprint is SHA256:KcA9xIWuTUKDaTduNWCtxFHGnbRNiOxeFfNaci45MqI.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:4022' (ECDSA) to the list of known hosts.
~# exit
logout
Connection to localhost closed.

Note: Note that if you restart the simulated machine, you may need to remove the line starting with '[localhost]:4022' in host file ~/.ssh/known_hosts to login with ssh again.
You can also access the minimal web server running on the simulated computer. Point your browser to the following address: http://localhost:4080. You should get something similar to figure 1.

Figure 1. A very simple page

Chapter 4 is the reference for everything related to real network connections.

2.1 Simple Virtual Network 3 Network Simulation