MultiSerial Mega

Two versions the FIRST is the original, the SECOND follows:

/*
  Mega multple serial test
 
 Receives from the main serial port, sends to the others. 
 Receives from serial port 1, sends to the main serial (Serial 0).
 
 This example works only on the Arduino Mega
 
 The circuit: 
 * Any serial device attached to Serial port 1
 * Serial monitor open on Serial port 0:
 
 created 30 Dec. 2008
 modified 20 May 2012
 by Tom Igoe & Jed Roach
 
 This example code is in the public domain.
 
 */


void setup() {
  // initialize both serial ports:
  Serial.begin(9600);
  Serial3.begin(9600);
}

void loop() {
  // read from port 3, send to port 0:
  if (Serial3.available()) {
    int inByte = Serial3.read();
    Serial.write(inByte);
   // Serial.println(inByte,DEC); 
  }
  
  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    Serial3.write(inByte); 
  }
}

SECOND for EtherDue 
/*
 Serial3 Server
 
 A simple server that distributes serial traffic from 3 serialports to all
 connected clients.  To use telnet to  your device's IP address and appropriate port.
 You can see the client's input in the serial monitor as well.
 Using an Arduino Wiznet Ethernet shield. 
 Serial 1 also goes to normal telnet port
 
 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 based on chatserver..
//on teensy shift CS(10) to 6 to avoid clash with serial.
// leave alone for Due/Freetronics
 
 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 modified 2015-2016 by Craig Benson UNSW ADFA
 can read, for example, in Safari by typing 192.168.1.177:50003 in address bar
 */

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);
IPAddress gateway(192,168,1, 1);
IPAddress subnet(255, 255, 0, 0);
int availGPSbytes=0;
const int bufflen=128;
char buff[bufflen];
int result=0;

//to add more serial servers, just write telnet to a different port for each.... ie
EthernetServer server1(50001);
EthernetServer server2(50002);
EthernetServer server3(50003);

// telnet defaults to port 23
EthernetServer server(23);
boolean alreadyConnected = false; // whether or not the client was connected previously

void setup() {
  //initialise the serial port to host PC (if there is one)
  Serial.begin(9600);
  // initialize the ethernet device for teensy
  delay(2000);
  pinMode(14,OUTPUT);
  //for (int i=1;i<1;i++){ //was 1:10
  //  if (result==0){
  //    digitalWrite(14,LOW);
  //    delay(50);
  //    digitalWrite(14,HIGH);
      delay(50);
      Ethernet.begin(mac, ip, gateway, subnet);
      delay(500);
        Serial.print("Cycled server address:");
  Serial.println(Ethernet.localIP());
  //  }
//  }
  // start listening for clients
  server.begin();
  server1.begin();
  server2.begin();
  server3.begin();
  
 // Open serial communications and wait for port to open:

  Serial1.begin(115200);
  Serial2.begin(115200);
  Serial3.begin(115200);
  
 //  while (!Serial) {
 //   ; // wait for serial port to connect. Needed for Leonardo only
 // }
delay(1000);
  Serial.print("Chat server address:");
  Serial.println(Ethernet.localIP());
}

void loop() {
  // wait for a new client:
  EthernetClient client = server.available();
//Serial.println("loop");
  // when the client sends the first byte, say hello:
//Serial.println("E\n");
  
  if (client) {
    if (!alreadyConnected) {
      // clead out the input buffer:
      client.flush();    
      Serial.println("We have a new client");
      client.println("Hello, client!"); 
      alreadyConnected = true;
    } 
//Serial.println("A\n");
    if (client.available() > 0) {
      // read the bytes incoming from the client:
//      Serial.println(client.available(),DEC);
      char thisChar = client.read();
      // echo the bytes back to the client:
      server.write(thisChar);
      // echo the bytes to the server as well:
 //     Serial.write(thisChar);
//Serial.println("B\n");

    }
  }
  //could repeat this 3 times for Serial1..3 and Server1..3
    availGPSbytes=min(Serial1.available(),bufflen);
 //   Serial.print("available bytes:");
 //   Serial.print(availGPSbytes,DEC);
 //int aa=Serial.available();
 //Serial.print("Serial available = ");
 //Serial.print(aa,DEC);
 //Serial.print("bufflen = ");
 //Serial.print(bufflen,DEC);
 //   Serial.println();
    if (availGPSbytes>0){
      Serial1.readBytes(buff,availGPSbytes);
      Serial.write(buff,availGPSbytes);
      //server.write(buff,availGPSbytes);
      server1.write(buff,availGPSbytes);
    }
  //serial 2, server 2 - do not use as serial #2 clashes with SPI CS **only on teensy**
  // solution is to remap serial 2 to pin 26 on rear of board
  // CORE_PIN26_CONFIG = PORT_PCR_MUX(RX2); from https://forum.pjrc.com/threads/25357-Serial2-on-pad-26-and-31-on-Teensy-3-1
  
    availGPSbytes=min(Serial2.available(),bufflen);
    if (availGPSbytes>0){
      Serial2.readBytes(buff,availGPSbytes);
      //Serial.readBytes(buff,availGPSbytes);
      //Serial.write(buff,availGPSbytes);
 /*     for (int k=1;k<availGPSbytes;k++) {
        Serial.print(buff[k],HEX);
        Serial.print(" ");
      }
      Serial.print("\n");
      //server.write(buff,availGPSbytes);*/
      server2.write(buff,availGPSbytes);
    } 
    
    //serial 3, server 3
    availGPSbytes=min(Serial3.available(),bufflen);
    if (availGPSbytes>0){
      Serial3.readBytes(buff,availGPSbytes);
      //Serial.write(buff,availGPSbytes);
      //server.write(buff,availGPSbytes);
      server3.write(buff,availGPSbytes);
    }
  
}